Skip to content

Non-null assertion mutates constrained type parameters (regression) #21438

Closed
@falsandtru

Description

@falsandtru

TypeScript Version: master

Search Terms:

Code

function f<T extends undefined | object>(o: T): T {
  return o!;
}

from https://github.com/falsandtru/typed-dom/blob/9e20f121ba0cc98da343a63deddeaae819d4a716/src/dom/html.ts#L36-L41

An argument o?: T is T | undefined but o! isn't T.

Expected behavior:

pass

Actual behavior:

$ node built/local/tsc.js --noEmit --strictNullChecks index.ts
index.ts(2,3): error TS2322: Type 'object' is not assignable to type 'T'.

Related Issues:

#21369?

cc @ahejlsberg @weswigham

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions