-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
feat(typing): use keyof inference to simplify definition #7797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 😄
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:
dev
branch for v2.x (or to a previous version branch), not themaster
branchfix #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.