Skip to content

No excess property error for computed property #36920

Open
@jcalz

Description

@jcalz

TypeScript Version: 3.7.5 and 3.9.0-dev.20200220

Search Terms: excess property, computed property, index signature

Code

interface Foo {
	a: string;
} 

const bar: Foo = {
	a: "",
	z: "" // error, excess prop
}

const baz: Foo = {
	a: "",
	["Z".toLowerCase()]: "" // this is okay I guess?
}

Expected behavior:
The computed property in the definition of baz should maybe produce an excess property error, since Foo has no string index signature and "Z".toLowerCase() is only known to be a string.

Actual behavior:
The computed property is allowed.

Playground Link: Here

Related Issues: #22427

This issue is a re-opening of #22427, which was marked as a bug and closed as "fixed", but I don't see an actual fix referenced anywhere in that issue and the behavior described in that issue persists. Any ideas? Thanks!

There's an SO question asking this, which brought me to #22427, which has me scratching my head 😕.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions