Versions of VS Code:
https://i.sstatic.net/nd5cD.png
Experimenting with 'Type Narrowing' Code in VS Code has brought to my attention a discrepancy between the information provided by VS Code and TypeScript Playground:
In VS Code, it shows that the return type of Document.getElementById
is HTMLElement
:
https://i.sstatic.net/ogMCm.png
https://i.sstatic.net/rm2Ba.png
However, TypeScript Playground indicates that the return type of Document.getElementById
should be HTMLElement | null
:
https://i.sstatic.net/baLQ0.png
The variable el
is expected to have type HTMLElement | null
before null checking:
https://i.sstatic.net/iCX5K.png
After null checking, el
is expected to be narrowed down to type HTMLElement
:
https://i.sstatic.net/HrtfU.png
I've already updated the global typescript package to v4.0.2 and configured typescript.tsdk
to
/Users/<username>/.nvm/versions/node/v12.16.3/lib/node_modules/typescript/lib
in user settings.json
I've also enabled strict type-checking options:
/* Strict Type-Checking Options */
"strict": true,
// "noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
// "strictBindCallApply": true,
// "strictPropertyInitialization": true,
// "noImplicitThis": true,
"alwaysStrict": true,
Could there be some missing configuration in my tsconfig.json
?