Skip to content

Type intersection on type with nested type breaks extra properties error #29678

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
Emily opened this issue Feb 1, 2019 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@Emily
Copy link

Emily commented Feb 1, 2019

TypeScript Version: 3.4.0-dev.20190131 (I spot checked versions since 3.0.1, all had this issue

Search Terms: intersection extra properties

Code

type Problematic = { one?: string } & { nested?: { two?: string } }
function problem(input: Problematic) {}

// nested containing bad property unexpectedly doesn't cause error
problem({
  nested: {
    two: 'hello',
    bad: 123
  }
})

Expected behavior:
bad: 123 should cause an extra properties error.

Actual behavior:
bad: 123 does not cause the extra properties error.

Playground Link: expanded examples

Related Issues: #28642

For anyone tripped up by this, there's a convenient work-around:

type Merge<T extends object> = { [K in keyof T]: T[K] };
type Problematic = { one?: string } & { nested?: { two?: string } }
function problemGone(input: Merge<Problematic>) {}

// works as expected
problemGone({
  nested: {
    two: 'hello',
    bad: 123
  }
})
@jack-williams
Copy link
Collaborator

Duplicate of #13813

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 5, 2019
@typescript-bot
Copy link
Collaborator

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

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