Skip to content

Unexpected excess property error with intersection of index signaturesΒ #51875

Closed
@jcalz

Description

@jcalz

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions