We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeScript Version: 3.1.0-dev.20180829
Search Terms: this index narrowing generics
Code
type Keys = 'string' | 'number'; type Switch<T extends Keys> = T extends 'string' ? string : T extends 'number' ? number : never; interface Main<T extends Keys> { kind: T; value: Switch<this['kind']>; } let x: Main<Keys> = null as any; x.kind; x.value; if (x.kind === 'string') { x.kind; // Narrowed to "string" x.value; } else { x.kind; // Narrowed to "number" x.value; }
Expected behavior: In the first if block, x.value should be of type string. In the second if block, x.value should be of type number.
x.value
string
number
Actual behavior: In both cases x.value is not narrowed, despite x.kind narrowing successfully.
x.kind
Related Issues: #24085
The text was updated successfully, but these errors were encountered:
No branches or pull requests
TypeScript Version: 3.1.0-dev.20180829
Search Terms: this index narrowing generics
Code
Expected behavior:
In the first if block,
x.value
should be of typestring
. In the second if block,x.value
should be of typenumber
.Actual behavior:
In both cases
x.value
is not narrowed, despitex.kind
narrowing successfully.Related Issues: #24085
The text was updated successfully, but these errors were encountered: