Output from JavaScript operator typeof
should be type-checked as a string
#54887
Closed
4 of 5 tasks
Labels
Duplicate
An existing issue was already created
Uh oh!
There was an error while loading. Please reload this page.
Suggestion
π Search Terms
List of keywords you searched for before creating this issue:
typeof
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
The traditional
typeof
operator (not the TS one!) returns a string, but TypeScript does not always type-check it as such:Playground
When strict equality is used, I would expect the compiler to also throw
2367
and2839
when This seems to be the case forundefined
,null
, and{}
.π Motivating Example
This code is allowed, but I think TS should have caught it:
π» Use Cases
The output of
typeof
is often compared to other variables, and TS should make sure those variables are also strings, at least when using===
.The text was updated successfully, but these errors were encountered: