Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
falsandtru opened this issue Jan 28, 2018 · 2 comments
Closed

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

falsandtru opened this issue Jan 28, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@falsandtru
Copy link
Contributor

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

@ajafff
Copy link
Contributor

ajafff commented Jan 28, 2018

According to #21317 (comment) this is intended.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 29, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants