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: number}typeB={b?: string}typeMAP={a: A,b: B}functiongetProfilesForNetwork<NetworkextendskeyofMAP>(network: Network): MAP[Network]{if(network==='a'){return{a: 43}}if(network==='b'){return{b: 'bbbbb'}// ERROR - Property 'a' is missing in type '{ b: string; }' but required in type 'A'.(2322)// Network is generic over 'a' | 'b' so it can be only 1 of those values, the value should narrow the return type to B here}thrownewError('Unknown!')}
🙁 Actual behavior
TS expects the return type to be A & B.
🙂 Expected behavior
The network === 'a' / network === 'b' should narrow the return type and should be either A or B.
The text was updated successfully, but these errors were encountered:
Bug Report
Incorrectly narrowing type inside a generic function where the return type is indexed from an object.
🔎 Search Terms
Generics, Mapped types, index types
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
TS expects the return type to be
A & B
.🙂 Expected behavior
The
network === 'a' / network === 'b'
should narrow the return type and should be either A or B.The text was updated successfully, but these errors were encountered: