Description
openedon May 3, 2018
TypeScript Version:
Reproducible in 2.7.2 and 2.9.0-dev.20180502.
Irreproducible in 2.6.2
Search Terms:
Mapped types, Non-null assertion
Code
function f<A extends string>(p0: {[key in A]: {}|undefined}, p1: A) {
const v: {} = p0[p1]!;
}
Expected behavior:
No errors.
Actual behavior:
In 2.7.2:
error TS2322: Type '{ [key in A]: {} | undefined; }[A]' is not assignable to type '{}'.
Type '{} | undefined' is not assignable to type '{}'.
Type 'undefined' is not assignable to type '{}'.
In 2.9.0-dev.20180502:
error TS2322: Type 'NonNullable<{ [key in A]: {} | undefined; }[A]>' is not assignable to type '{}'.
Type '{} | undefined' is not assignable to type '{}'.
Type 'undefined' is not assignable to type '{}'.
Playground Link:
I cannot reproduce the error in the playground.
From command line, I'm running node_modules/.bin/tsc -strict test.ts
to reproduce it.
Related Issues:
#19608