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
This bug also exists in the TypeScript compiler - I don't know if you use it directly or have your own code. In the following TypeScript file, named bug.ts:
export enum SynCat {
INDENT,
UNDENT
}
export type Token = string | SynCat
function fileHandler(lTokens: Token[]): void {
if (lTokens[0] === SynCat.INDENT) {
lTokens.shift()
while (lTokens[0] !== SynCat.UNDENT) {
const tok = lTokens.pop()
}
}
return
}
When I run deno test bug.ts, I get the message:
TS2367 [ERROR]: This comparison appears to be unintentional because the types 'SynCat.INDENT' and 'SynCat.UNDENT' have no overlap.
while (lTokens[0] !== SynCat.UNDENT) {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think it's assuming that lTokens[0] has value SynCat.INDENT because of the preceding if check. However, inside that if statement that value of lTokens is modified by shifting off a value, and therefore, lTokens[0] has been modified. So, the comparison of lTokens[0] with SynCat.UNDENT is valid, i.e. not superfluous.
I suspect that the code will still run, but the message is wrong (unless I'm missing something). Also, it's reported as an ERROR, not a WARNING.
I did a search of TypeScript issues, and this may be related to #9998.
The text was updated successfully, but these errors were encountered:
Closing as there isn't much we can do on our end. In general we don't extend the TypeScript language and leave that up to the TypeScript team. The upstream issue is here: microsoft/TypeScript#9998
$ deno --version
deno 2.2.5 (stable, release, x86_64-pc-windows-msvc)
v8 13.5.212.4-rusty
typescript 5.7.3
This bug also exists in the TypeScript compiler - I don't know if you use it directly or have your own code. In the following TypeScript file, named
bug.ts
:When I run
deno test bug.ts
, I get the message:I think it's assuming that lTokens[0] has value SynCat.INDENT because of the preceding
if
check. However, inside thatif
statement that value of lTokens is modified by shifting off a value, and therefore, lTokens[0] has been modified. So, the comparison of lTokens[0] with SynCat.UNDENT is valid, i.e. not superfluous.I suspect that the code will still run, but the message is wrong (unless I'm missing something). Also, it's reported as an ERROR, not a WARNING.
I did a search of TypeScript issues, and this may be related to #9998.
The text was updated successfully, but these errors were encountered: