Skip to content
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

fix(types): infer discriminated unions in child component props #3672

Merged
merged 6 commits into from
Oct 22, 2023

Conversation

davidmatter
Copy link
Collaborator

@davidmatter davidmatter commented Oct 16, 2023

This fixes vuejs/core#9381

Like the fix in vue/core vuejs/core#9336 we use an alternative Omit that doesn't break discriminated unions in props. More information can be found here: microsoft/TypeScript#31501

Comment on lines 380 to 385
codes.push(
`type OmitKeepDiscriminatedUnion<T, K extends keyof any> = T extends any`,
`? Pick<T, Exclude<keyof T, K>>
: never`,
`;\n`,
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this could be defined in https://github.com/vuejs/language-tools/blob/master/packages/vue-language-core/src/utils/globalTypes.ts since it doesn't depend on any dynamic code.

(I'm not super familiar with this project so you might wait for confirmation on that)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, thanks. Done

@johnsoncodehk
Copy link
Member

LGTM, thanks!

@johnsoncodehk johnsoncodehk merged commit 2a44b10 into vuejs:master Oct 22, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Types: type narrowing not work in parent component when child component use union type to defineProps
3 participants