feat(typing): use keyof inference to simplify definition#7797
feat(typing): use keyof inference to simplify definition#7797HerringtonDarkholme wants to merge 1 commit intovuejs:2.6from
Conversation
|
@yyx990803, I haven't tried this yet, but I think the TypeScript template in vue-cli should have this in the box if possible. |
|
Though, wait @HerringtonDarkholme, doesn't this mean that every type in props ends up being |
|
@DanielRosenwasser @sandersn has a following fix to infer |
|
There's a flow error causing the TS test to be skipped. Can we rebase against latest |
cf99a77 to
8ff017f
Compare
|
@HerringtonDarkholme this PR seems to have been messed up by force pushes. The type tests are failing after manual cherry-picking locally - can you take another look? |
8ff017f to
1f423d6
Compare
|
It looks like TypeScript has added a new inference priority for literal type as in https://github.com/Microsoft/TypeScript/pull/22525/files. This means But it does not simplify our type definition. |
|
In short, we cannot achieve simpler definition in 2.6. But we probably can rewrite the definition in Vue 3.0 with conditional types! I have used in my own project and it works quite well. As for now, let's close this issue. |
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
devbranch for v2.x (or to a previous version branch), not themasterbranchfix #xxx[,#xxx], where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Our typing is very complex. This pull request uses the new feature from TS 2.7 to combine record style and array style prop definition into one. microsoft/TypeScript#19227
A simpler type definition should be beneficial to both our users and we maintainers.
Kudos to @sandersn @DanielRosenwasser !
Note: this requires TS 2.7+. So it is expected to be included in a minor version update.