Skip to content

Error "Object literal may only specify known properties" is not happening in all cases with intersection types #18075

Closed
@asfernandes

Description

@asfernandes

TypeScript Version: 2.4.2

export type MyType =
	{
		id: number;
	}
	&
	{
		name: string;
	}
	&
	{
		photo:
		{
			id: number;
		}
		&
		{
			url: string;
		}
	}


export let obj: MyType;

export const photo: typeof obj.photo = {
	id: 1,
	url: '',
	xyz: 1	// Great! This causes an error!
};
	
export const myInstance: MyType = {
	id: 1,
	name: '',
	photo: {
		id: 1,
		url: '',
		xyz: 2	// Bug? This does not cause an error!!!
	}
};

Expected behavior:

I expect all attributions to xyz to give an error.

Actual behavior:

TypeScript is accepting one of the attributions to xyz (with value 2).

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions