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

Intersection Type, properties not excluded from index signature #24300

Closed
cpamp opened this issue May 21, 2018 · 1 comment
Closed

Intersection Type, properties not excluded from index signature #24300

cpamp opened this issue May 21, 2018 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@cpamp
Copy link

cpamp commented May 21, 2018

TypeScript Version:
2.8.3

Search Terms:
intersection type index

Code

interface ExcludedIndex {
	excluded: number;
}

interface Index {
	[key: string]: string;
}

type Combined = ExcludedIndex & Index;

const obj: Combined = {
	anyString: "",
	excluded: 0
}

Expected behavior:
No Errors - should be able to assign excluded to obj.

Actual behavior:
Error:

[ts]
Type '{ anyString: string; excluded: number; }' is not assignable to type 'Combined'.
Type '{ anyString: string; excluded: number; }' is not assignable to type 'Index'.
Property 'excluded' is incompatible with index signature.
Type 'number' is not assignable to type 'string'.

Playground Link:
Link

Related Issues:
#24220 #23673 #20597

@mhegazy
Copy link
Contributor

mhegazy commented May 21, 2018

This the behavior of intersection types.

Duplicate of #17867

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 21, 2018
@cpamp cpamp closed this as completed May 22, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants