Microsoft/TypeScript
Ver no GitHubDestructuring into an empty object vs an object with existing properties yields different results
Open
#60.386 aberto em 31 de out. de 2024
BugDomain: check: Excess Property CheckingHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
🔎 Search Terms
"destructuring", "record"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ.
⏯ Playground Link
💻 Code
This raises a type error:
const recordWithStrings: Record<string, string> = {};
export const recordWithNumbers: Record<string, number> = {
...recordWithStrings,
};
and this doesn't:
const recordWithStrings: Record<string, string> = {};
export const recordWithNumbers: Record<string, number> = {
extraProperty: 0,
...recordWithStrings,
};
Is there a sound reason for that?
🙁 Actual behavior
The 2nd example doesn't raise a type error.
🙂 Expected behavior
The 2nd example should raise a type error.
Additional information about the issue
No response