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 came across a case where the type could obviously be narrowed down. but for some reason typescript doesn't support this. it was a frustrating experience
π Motivating Example
Here is code example
typeT='a'|"b"typeM={a: 1,b: 2}functionf1(a: 'a'){}functionf2(a: 1){}functionf<TTextendsT>(t: TT,p: M[TT]){switch(t){case"a": {f1(t);f2(p);// Argument of type '1 | 2' is not assignable to parameter of type '1'. Type '2' is not assignable to type '1'.break}}}
π» Use Cases
I want to write more clear code without workarounds
Current approach isn't intuitive
I'm using type casts as workaround in the meantime
The text was updated successfully, but these errors were encountered:
π Search Terms
"type narrowing for mapped type", "type narrowing for mapped argument", "type narrowing for generic mapped argument"
β Viability Checklist
β Suggestion
I came across a case where the type could obviously be narrowed down. but for some reason typescript doesn't support this. it was a frustrating experience
π Motivating Example
Here is code example
π» Use Cases
The text was updated successfully, but these errors were encountered: