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
exporttypeIEntrie=(['a',string]|['b',string]|['c',string]|['d',string]|['e',number])exportdefault(Object.entries({})asIEntrie[]).map(([siteID,table])=>{if(siteID==='e'){console.dir(siteID)// infer should is 'econsole.dir(table+0)// infer should is numberreturn{
siteID,
table,}}else{console.dir(siteID)// infer should is a b c dconsole.dir(table)// infer should is stringreturn{
siteID,
table,}}})
Expected behavior:
when siteID is e, table should is number, not string | number
when siteID is not e, table should is string, not string | number
Duplicate of #32639 which is a duplicate of #12184. My search terms were "dependent narrowing".
Everything works as expected if you don't destructure into [siteID, table], but once you do you have two separate variables and Typescript doesn't track the relation between narrowing one causing a narrowing of the other.
TypeScript Version: Version 3.8.0-dev.20200123
Search Terms:
Code
Expected behavior:
when siteID is
e
,table
should isnumber
, notstring | number
when siteID is not
e
,table
should isstring
, notstring | number
Actual behavior:
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: