Skip to content

No excess property error for computed property #22427

Closed
@Mitko-Kerezov

Description

@Mitko-Kerezov

TypeScript Version: 2.8.0-dev.20180308

Search Terms: Interface, known property

Code

interface IDictionary<T> {
	[key: string]: T
}
interface ITestInterface {
	booleanMap?: IDictionary<boolean>;
	otherProperty: number;
}

const someArg: string = "testString";
const textObject: ITestInterface = {
	[someArg]: true,
	otherProperty: 5
}

Expected behavior:
An error because ITestInterface does not include a definition for [key: string]: boolean. A correct object implementing ITestInterface would be:

const textObject: ITestInterface = {
	booleanMap: {
		[someArg]: true
	},
	otherProperty: 5
}

I expected some sort of:
error TS2322: Type '{ [someArg]: boolean; otherProperty: number; }' is not assignable to type 'ITestInterface'. Object literal may only specify known properties, and '[someArg]' does not exist in type 'ITestInterface'.
error
Actual behavior:
Transpiled successfully - no errors.

Playground Link: Here

Related Issues: I'm not sure about any related issues

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions