We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript Version: 3.1.0-dev.201xxxxx
Search Terms: generics, typeof, object, never
Code
function f<TData>(data: TData): boolean { if (typeof data === "object") return true; return data; } let x: boolean = f(1);
Expected behavior: Code should not compile - function actually returns boolean | TData, but states only boolean
Actual behavior: Code compiles without errors. After the if statement, data is considered never
Playground Link: http://www.typescriptlang.org/play/#src=function%20f%3CTData%3E(data%3A%20TData)%3A%20boolean%20%7B%0D%0A%20%20%20%20if%20(typeof%20data%20%3D%3D%3D%20%27object%27)%0D%0A%20%20%20%20%20%20%20%20return%20true%3B%0D%0A%20%20%20%20return%20data%3B%0D%0A%7D%0D%0A%0D%0Alet%20x%3A%20boolean%20%3D%20f(1)%3B
Related Issues:
The text was updated successfully, but these errors were encountered:
This is fixed by #27157.
Sorry, something went wrong.
ahejlsberg
No branches or pull requests
TypeScript Version: 3.1.0-dev.201xxxxx
Search Terms: generics, typeof, object, never
Code
Expected behavior:
Code should not compile - function actually returns boolean | TData, but states only boolean
Actual behavior:
Code compiles without errors. After the if statement, data is considered never
Playground Link: http://www.typescriptlang.org/play/#src=function%20f%3CTData%3E(data%3A%20TData)%3A%20boolean%20%7B%0D%0A%20%20%20%20if%20(typeof%20data%20%3D%3D%3D%20%27object%27)%0D%0A%20%20%20%20%20%20%20%20return%20true%3B%0D%0A%20%20%20%20return%20data%3B%0D%0A%7D%0D%0A%0D%0Alet%20x%3A%20boolean%20%3D%20f(1)%3B
Related Issues:
The text was updated successfully, but these errors were encountered: