-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type simultaneously does and does not have property #30657
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
Comments
It even works if you do:
|
There's definitely something odd going on here. It appears related to the type ChannelOfType<T extends ChannelType> =
T extends 'text' ? TextChannel :
T extends 'email' ? EmailChannel :
never; |
OK, so this is only strange because we have two completely different types which instantiate to the same alias symbol and alias type arguments; under the hood we actually are talking about two completely separate types. type NewChannel<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>> =
& Pick<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>, "type">
& Partial<Pick<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>, (
| ({ [P in keyof ChannelOfType<T, TextChannel>]: P; } & { type: never; id: never; } & { [x: string]: never; })
| ({ [P in keyof ChannelOfType<T, EmailChannel>]: P; } & { type: never; id: never; } & { [x: string]: never; })
)[keyof ChannelOfType<T, TextChannel> & keyof ChannelOfType<T, EmailChannel>]>>
& { localChannelId: string; } if you stop printing type NewChannel<TextChannel> =
& Pick<TextChannel, "type">
& Partial<Pick<TextChannel, (
| ({ [P in keyof TextChannel]: P; } & { type: never; id: never; } & { [x: string]: never; })
| ({ [P in keyof never]: P; } & { type: never; id: never; } & { [x: string]: never; })
)[keyof TextChannel & never]>>
& { localChannelId: string; } OK, now what's gone wrong should be obvious - |
TypeScript Version: 3.4.1 and 3.2.2
Code
Expected behavior:
Since
newTextChannel
andnewTextChannel2
are both of typeNewChannel<TextChannel>
, I'd expect them both to have aphoneNumber
property (or both to not have aphoneNumber
property).Actual behavior:
newTextChannel
does not have this property, andnewTextChannel2
does, even though these two seem to be of the same type!Playground Link: link
Related Issues: No
The text was updated successfully, but these errors were encountered: