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

Type of object spread properties is incorrectly inferred with strictNullChecks #21698

Closed
MartinJohns opened this issue Feb 6, 2018 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@MartinJohns
Copy link
Contributor

TypeScript Version: 2.7.1

Search Terms:

  • partial
  • strictNullChecks
  • undefined

Code

interface User {
    name: string;
}

const user: User = { name: 'Bob' };
const partial: Partial<User> = { name: undefined };
const result = { ...user, ...partial };

type ResultName = (typeof result)['name'];

Expected behavior:
Type ResultName is string | undefined.

Actual behavior:
Type ResultName is string.

Playground Link:
https://www.typescriptlang.org/play/#src=%0D%0Ainterface%20User%20%7B%0D%0A%20%20%20%20name%3A%20string%3B%0D%0A%7D%0D%0A%0D%0Aconst%20user%3A%20User%20%3D%20%7B%20name%3A%20'Bob'%20%7D%3B%0D%0Aconst%20partial%3A%20Partial%20%3D%20%7B%20name%3A%20undefined%20%7D%3B%0D%0Aconst%20result%20%3D%20%7B%20...user%2C%20...partial%20%7D%3B%0D%0A%0D%0Atype%20ResultName%20%3D%20(typeof%20result)%5B'name'%5D%3B%0D%0A

Related Issues:
#14799

@mhegazy
Copy link
Contributor

mhegazy commented Feb 6, 2018

Seems like a duplicate of #13195

@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 6, 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

3 participants