Open CoderMuffin opened 5 months ago
This is a great idea! I'll put 12$ on it.
Hey Strager, I would love to try and tackle this issue!
@milanjijo are you working on this task?
@strager Is there any way to currently check a string literal against this list ("undefined", "object", "boolean", "number", "bigint", "string", "symbol" or "function") in the code?
@singalhimanshu yes, you can compare the Expression::Literal->span()->string_view() to each element of the array. The detection code for a similar diagnostic which might help can be seen here: src/quick-lint-js/fe/parse.cpp:524
When performing checks like
typeof x == "string"
, it is perfectly possible to misspell it as something liketypeof x == "strng"
(missingi
), which will always return false. Maybe there should be a warning for this?More generally, expressions of the form
typeof <a> [== or != or === or !==] <b>
where b is a string and not"undefined"
,"object"
,"boolean"
,"number"
,"bigint"
,"string"
,"symbol"
or"function"
I would be happy to implement this if approved and no-one else wants to :)