Skip to content
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

Object spread not checking for strictNullChecks #14799

Closed
thitemple opened this issue Mar 22, 2017 · 4 comments
Closed

Object spread not checking for strictNullChecks #14799

thitemple opened this issue Mar 22, 2017 · 4 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@thitemple
Copy link

TypeScript Version: 2.2.1

Code

type Movie = {
	title: string;
	yearReleased: number;
}

const m = { title: "The Matrix", yearReleased: 1999 };
const x: Movie = { ...m, title: undefined };

Expected behavior:
When strictNullChecks = true it should not allow for title = undefined
Actual behavior:
It does not raise an error and I can have an object with a required property undefined.
It does work if I try to set null to title, the compiler will raise an error

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 22, 2017
@mprobst
Copy link
Contributor

mprobst commented May 5, 2017

Similar, but might be a different bug:

const x: {a: number}|null = null;
const y = {...x};

With strictNullChecks, this should complain about x being possibly null at the spread location (in ES6 or with downlevelIteration this also gives a TypeError).

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2017

With strictNullChecks, this should complain about x being possibly null at the spread location (in ES6 or with downlevelIteration this also gives a TypeError).

The semantics of object spread allows for skipping null and undefined values, see https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md. It is meant to follow the Object.assign semantics.

The __assign polyfill handles that accordingly.

@mhegazy mhegazy added this to the TypeScript 2.4 milestone May 5, 2017
@mprobst
Copy link
Contributor

mprobst commented May 13, 2017

@mhegazy sorry, incorrect example, and I found that the usage site I ran into actually used ! (so, self inflicted pain...).

@sandersn sandersn added this to Not started in Rolling Work Tracking May 16, 2017
@sandersn sandersn moved this from Not started to In Progress in Rolling Work Tracking May 17, 2017
@sandersn sandersn moved this from In Progress to Not started in Rolling Work Tracking May 17, 2017
@sandersn sandersn moved this from Not started to In Progress in Rolling Work Tracking May 18, 2017
@sandersn sandersn added the Fixed A PR has been merged for this issue label May 18, 2017
@sandersn
Copy link
Member

Fix is up at #15938

@sandersn sandersn moved this from In Progress to Done in Rolling Work Tracking May 18, 2017
@sandersn sandersn removed this from Done in Rolling Work Tracking Jun 6, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants