Microsoft/TypeScript
GitHub ã§èŠãDestructuring into an empty object vs an object with existing properties yields different results
Open
#60,386 opened on 2024幎10æ31æ¥
BugDomain: check: Excess Property CheckingHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð 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