TypeScript Version: 3.5.0-dev.20190411
Search Terms:
Indexed Access Types
Lookup Types
strictNullChecks
Code
typeFoo={bar: undefined}|{bar: string};constb1: {bar: Foo["bar"]}={bar: undefined};constb2: Foo=b1;constb3: Foo={bar: undefined};Expected behavior:
This should compile with strictNullChecks on. I expect {bar: Foo["bar"]} to be the same thing as Foo in this case.
Actual behavior:
running tsc --strictNullChecks .\bug.ts result in:
bug.ts:4:7 - error TS2322: Type '{ bar: string | undefined; }' is not assignable
to type 'Foo'.
Type '{ bar: string | undefined; }' is not assignable to type '{ bar: string;
}'.
Types of property 'bar' are incompatible.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
4 const b2: Foo = b1;
~~
Found 1 error.
Playground Link:Link
Related Issues:
#29042
#21975 This one is extremely similar but it and the ones it was marked as a duplicate of were closed. Is this a regression?
TypeScript Version: 3.5.0-dev.20190411
Search Terms:
Indexed Access Types
Lookup Types
strictNullChecks
Code
Expected behavior:
This should compile with
strictNullCheckson. I expect{bar: Foo["bar"]}to be the same thing asFooin this case.Actual behavior:
running
tsc --strictNullChecks .\bug.tsresult in:Playground Link:Link
Related Issues:
#29042
#21975 This one is extremely similar but it and the ones it was marked as a duplicate of were closed. Is this a regression?