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
First encountered in tsc 3.9.7, just verified in the playground with v4.2.3
This is the behavior in every version I tried, and I reviewed the FAQ for entries about everything (I read the whole FAQ and didn't find anything that seemed to match the kind of thing I'm talking about here)
constfooMap=newMap<string,string>();functionexample(key: string,value: string): ()=>string{lets=fooMap.get(key);if(s===undefined){s=value;}constt=s;return()=>s;// replace s with t here to make the error go away}
🙁 Actual behavior
On the final line of the sample (the return statement), TS complains:
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
even though at the location in question s is certain to be of type string.
If you replace s with t, defined on the line immediately above the return statement, the error goes away.
🙂 Expected behavior
tsc should not whine about a type error on that return statement.
The text was updated successfully, but these errors were encountered:
Bug Report
🔎 Search Terms
typescript type inference failures
🕗 Version & Regression Information
First encountered in tsc 3.9.7, just verified in the playground with v4.2.3
⏯ Playground Link
Here
💻 Code
🙁 Actual behavior
On the final line of the sample (the
return
statement), TS complains:even though at the location in question
s
is certain to be of typestring
.If you replace
s
witht
, defined on the line immediately above the return statement, the error goes away.🙂 Expected behavior
tsc should not whine about a type error on that return statement.
The text was updated successfully, but these errors were encountered: