You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tried my best to search for related issues and read the documentation thoroughly but failed to find any useful information. I'm sorry if this bug turns out to be duplicate or even not a bug at all.
typeFoo<Textendsnumber|string>={value: T;}typeNarrow<Textendsnumber|string|undefined>=Textendsundefined ? never : Foo<T>;// ^// ERROR: Type 'string | number | undefined' is not assignable to type 'string | number'.
🙁 Actual behavior
In the above example, T throws an error when passed to Foo because the compiler believes T could be undefined.
🙂 Expected behavior
The condition has checked if T extends undefined so I would expect T's type to be narrowed from string | number | undefined to string | number on the right side of the ternary operator.
The text was updated successfully, but these errors were encountered:
Bug Report
I've tried my best to search for related issues and read the documentation thoroughly but failed to find any useful information. I'm sorry if this bug turns out to be duplicate or even not a bug at all.
🔎 Search Terms
conditional type if undefined
🕗 Version & Regression Information
All versions available in the playground (http://www.typescriptlang.org/play)
⏯ Playground Link
Playground link
💻 Code
🙁 Actual behavior
In the above example,
T
throws an error when passed toFoo
because the compiler believesT
could be undefined.🙂 Expected behavior
The condition has checked if
T
extends undefined so I would expectT
's type to be narrowed fromstring | number | undefined
tostring | number
on the right side of the ternary operator.The text was updated successfully, but these errors were encountered: