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
exportfunctionreturnAnyString(): string{return"";}exportfunctionacceptsOnlyFoo(value: "foo"): void{// ...}constvalue=returnAnyString();if(value==="foo")acceptsOnlyFoo(value);// error TS2345: Argument of type 'string' is not assignable to parameter of type '"foo"'.
Expected behavior:
The === to narrow type string to a string literal type when checking for equality with a string literal. I would expect the above example to be the same as the following example which does work...
exportfunctionreturnAnyString(): string{return"";}exportfunctionacceptsOnlyFoo(value: "foo"): void{// ...}functionisFoo(s: string): s is "foo"{returns==="foo";}constvalue=returnAnyString();if(isFoo(value))acceptsOnlyFoo(value);
Actual behavior:
The type is still string.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.1.0-dev.20160918
Code
Expected behavior:
The
===
to narrow typestring
to a string literal type when checking for equality with a string literal. I would expect the above example to be the same as the following example which does work...Actual behavior:
The type is still
string
.The text was updated successfully, but these errors were encountered: