Skip to content

Non-null assertion doesn't work for mapped types #23849

Closed

Description

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

@rkirov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions