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
typeA={a: 'a';b: number;x: number}|{a: 'b';c: string;x: number;}typeNoX<T>=Omit<T,'x'>;// Works as expectedfunctionf1(p: A){switch(p.a){case'a':
console.log(p.b);break;case'b':
console.log(p.c);break;}}// Has type errors even though there is no reason for itfunctionf2(p: NoX<A>){switch(p.a){case'a':
console.log(p.b);break;case'b':
console.log(p.c);break;}}
π Actual behavior
TypeScript does not realize that the member p.b exists if p.a === 'a' in the function f2
π Expected behavior
The function f2 should typechek without errors, since it does not in any way touch or care about the removed member x.
The text was updated successfully, but these errors were encountered:
Bug Report
Sometimes narrowing of discriminated unions fails with mapped types. See the attached playground
π Search Terms
narrowing mapped types
π Version & Regression Information
Happens in latest. don't know about other versions.
β― Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAglC8UDeUCGAuKByVWDcUARpgHYCuAtoRAE4EAepl1NUAvlAD7JqZaH4oAY0wBnYDQCWJAOYMmVWgTYAoFaEhQAcgHsAGgB4AKgD4EUAPIVJwYwBps9LCbxqA9G6gB1HTQDWomiBEPSQQsAQACYqAGZkJOGSOiRQMQCMABRgmDAAlMgqUFCiAO42QgAWUFkAdKj5SIVFwqii0DhY6E3NwsmiOgA2EDUDOjK1hLmuPUWENBCoftPNQq3tAl0zvST9QyNjtUJT3c1zC0tNqqoqHlAAEq1QGtC0NL7BAG4QKcAVOmQyKq-WjQSSBEg6KDzVrJVK+KA2WLxRKwmIAJiymF0hhgJgaTVK5SqtXqBR6qza2FwmxmQj6g2Go3GYBqk2WPTOi3ZLUp-E6JyKdJ2DP2zJqR25s2hFyKVxUQA
π» Code
π Actual behavior
TypeScript does not realize that the member
p.b
exists ifp.a === 'a'
in the functionf2
π Expected behavior
The function
f2
should typechek without errors, since it does not in any way touch or care about the removed memberx
.The text was updated successfully, but these errors were encountered: