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

Unexpected excess property error with intersection of index signatures #51875

Closed
jcalz opened this issue Dec 13, 2022 · 1 comment Β· Fixed by #51894
Closed

Unexpected excess property error with intersection of index signatures #51875

jcalz opened this issue Dec 13, 2022 · 1 comment Β· Fixed by #51894
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Milestone

Comments

@jcalz
Copy link
Contributor

jcalz commented Dec 13, 2022

Bug Report

πŸ”Ž Search Terms

index signature, intersection, excess property checking

πŸ•— Version & Regression Information

  • This changed between versions 4.8.0-dev.20220613 and 4.8.0-dev.20220614

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

let x: { [k: string]: { a: 0 } } & { [k: string]: { b: 0 } };

x = { y: { a: 0, b: 0 } } // error!
//               ~~~~  
// Object literal may only specify known properties, 
// and 'b' does not exist in type '{ a: 0; }'

x = { y: { a: 0 } } // error!
//    ~
// Property 'b' is missing in type '{ a: 0; }'

πŸ™ Actual behavior

The object literal { a: 0, b: 0 } is considered to have an excess property of b, but if you remove b then the compiler will complain that b is missing. It's a catch-22!

πŸ™‚ Expected behavior

The object literal { a:0, b: 0 } should be accepted.


This came from this Stack Overflow question. Looks like it started with #49503.

@fatcerberus
Copy link

Property b is missing in type { a: 0; }

Nice.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Dec 13, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Dec 13, 2022
@ahejlsberg ahejlsberg self-assigned this Dec 14, 2022
@ahejlsberg ahejlsberg removed the Help Wanted You can do this label Dec 14, 2022
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants