Skip to content

Spread operator ignores object type check #51400

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
aspic-fish opened this issue Nov 3, 2022 · 2 comments
Closed

Spread operator ignores object type check #51400

aspic-fish opened this issue Nov 3, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@aspic-fish
Copy link

Bug Report

πŸ”Ž Search Terms

spread operator object wrong type

πŸ•— Version & Regression Information

This is the behavior in every version I tried up to 5.0.0-dev.20221103

⏯ Playground Link

Playground

πŸ’» Code

An object type can be assigned with any other object type via spread operator without any errors

const foo: {} = {
  ...{
    foo: 'bar'
  },
  ...['including arrays'],
};

for arrays it works as expected

// type number[] is not assignable to type []
const arr: [] = [  
  ...[1,2,3,4,5,6,7]
];
// no error, ok
const arr2: [1] = [
  ...[1] as [1]
];

in the following code t property is infered correctly, but no error

const f = (arg: {[key: string]: {foo: 'bar'}}) => {}
f({
  t: {
    foo: 'bar',
    ...{bar: 'baz'}, // no error, wrong
    // bar: 'baz', // error, ok
  }
})

Screenshot 2022-11-03 233547

πŸ™ Actual behavior

Spread operator ignores object type

πŸ™‚ Expected behavior

Spread operator must respect object type

@MartinJohns
Copy link
Contributor

Duplicate of #39998.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 3, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants