Closed as duplicate of#32693
Closed as duplicate of#32693
Description
π Search Terms
strictNullChecks "not assignable" "to type 'undefined'"
π Version & Regression Information
- This changed between versions 3.3.3 and 3.5.1
All newer versions have this behavior
β― Playground Link
π» Code
interface NodeProps {
a?: number;
b?: string;
}
const original: NodeProps = {};
const target: NodeProps = {};
let prop1: keyof NodeProps = 'a';
target[prop1] = original[prop1]; // works
let prop2: keyof NodeProps = 'a' as keyof NodeProps;
target[prop2] = original[prop2]; // Error
const props: Array<keyof NodeProps> = [];
for (const prop of props) {
target[prop] = original[prop]; // Error
}
π Actual behavior
Got unexpected errors:
Type 'string | number | undefined' is not assignable to type 'undefined'.
Type 'string' is not assignable to type 'undefined'.
π Expected behavior
Should produce no errors
Additional information about the issue
Seems to be closely related to #59969 - disabling strictNullChecks
option changes the error text, but essentially error stays the same.
Error produced with strictNullChecks
:
Type 'string | number' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.
Metadata
Metadata
Assignees
Labels
No labels