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

Spread object type checking #12753

Closed
PavelPZ opened this issue Dec 8, 2016 · 3 comments
Closed

Spread object type checking #12753

PavelPZ opened this issue Dec 8, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@PavelPZ
Copy link

PavelPZ commented Dec 8, 2016

TypeScript Version: 2.1.4

Code

interface IPerson {
  name: string;
}

let person: IPerson = { name: 'John' };
let person2: IPerson;

person2 = { name: 'John', age:34 }; //error!!!!
person2 = { ...person, age: 34 }; //no error!!!!

Question
Is person2 = { ...person, age: 34 }; //no error!!!! expected behavior?

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Dec 8, 2016

I think this is expected behavior. These are not object literals but rather expressions that produce a value that is a subtype of their constituents.

@PavelPZ
Copy link
Author

PavelPZ commented Dec 8, 2016

OK, thanks, but is there any other solution how to avoid typing errors, e.g.:

person2 = { ...person, xname: 'Charles' };

@mhegazy
Copy link
Contributor

mhegazy commented Dec 8, 2016

Duplicate of #12717

@mhegazy mhegazy added the Duplicate An existing issue was already created label Dec 8, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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