Encountering the peculiar behavior of TS.
const isItLanding = false;
if (isItLanding === undefined) { // valid
return ...;
}
However, in this instance
const isItLanding = 1;
if (isItLanding === 'undefined') { // error
return ...;
}
Why does TS not prevent writing incorrect comparisons? And what steps can be taken to modify this behavior?
The configuration of my TS appears as follows:
{
"compilerOptions": {
"strict": true,
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"importsNotUsedAsValues": "error",
"allowSyntheticDefaultImports": true,
"incremental": true,
"tsBuildInfoFile": ".next/cache/.tscache/",
"jsx": "preserve",
"sourceMap": true,
"baseUrl": ".",
"paths": {
"~/*": ["src/*"],
"test-utils": ["./src/client/test-utils"]
}
},
"exclude": ["node_modules", "cypress"]
}