TypeScript Version: 3.6.2
Search Terms: TS2322 Invalid assignment error
Code

{
"compilerOptions": {
"outDir": "dist",
"allowJs": true,
"checkJs": true,
"downlevelIteration": true,
"emitBOM": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"module": "ESNext",
"noEmitOnError": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"sourceMap": true,
"strict": true,
"target": "es5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node"
},
"include": [
"./app/",
"./scripts/"
]
}
Expected behavior:
The assignment should be valid, because both sides of the assignment as declared as string | null.
Actual behavior:
TypeScript raises the error message:
TS2322: Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.
Playground Link: Sorry, no playground link. I don't know nor do I understand what causes the false behaviour on this particular assignment.
Related Issues: ./.
TypeScript Version: 3.6.2
Search Terms: TS2322 Invalid assignment error
Code
{ "compilerOptions": { "outDir": "dist", "allowJs": true, "checkJs": true, "downlevelIteration": true, "emitBOM": true, "forceConsistentCasingInFileNames": true, "noImplicitAny": true, "module": "ESNext", "noEmitOnError": true, "noUnusedLocals": true, "noUnusedParameters": true, "preserveConstEnums": true, "sourceMap": true, "strict": true, "target": "es5", "emitDecoratorMetadata": true, "experimentalDecorators": true, "moduleResolution": "node" }, "include": [ "./app/", "./scripts/" ] }Expected behavior:
The assignment should be valid, because both sides of the assignment as declared as
string | null.Actual behavior:
TypeScript raises the error message:
Playground Link: Sorry, no playground link. I don't know nor do I understand what causes the false behaviour on this particular assignment.
Related Issues: ./.