Skip to content

types typescript does not work when using the spread operator #60182

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
anzor1qqqqq opened this issue Oct 10, 2024 · 4 comments
Closed

types typescript does not work when using the spread operator #60182

anzor1qqqqq opened this issue Oct 10, 2024 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@anzor1qqqqq
Copy link

πŸ”Ž Search Terms

types typescript, spread operator

πŸ•— Version & Regression Information

in all version typscript

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAZgSwE7RgXhgbwLACgYEwCGA5gKYBcMATNXgL556iSxFU76FhEC2lMaEgRgSDdFjyEYAOjmIUUADRTufAQHIiYAF4gkGhkA

πŸ’» Code

const first = {
age: 22
}

const a: {
name: string
} = {
...first,
name: 'anzor'
}

πŸ™ Actual behavior

the compiler does not cause an error in the second object type

πŸ™‚ Expected behavior

the ts compiler should warn about the type mismatch

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

Duplicate of #39998. Excess property checks are not performed when spreading.

There is no type mismatch. Additional properties are allowed to exist on objects.

@anzor1qqqqq
Copy link
Author

Duplicate of #39998. Excess property checks are not performed when spreading.

There is no type mismatch. Additional properties are allowed to exist on objects.

How can this be defeated??????????

@MartinJohns
Copy link
Contributor

It's a fundamental part of TypeScripts type system, it's intentional.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 10, 2024
@typescript-bot
Copy link
Collaborator

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

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2024
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