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

Error with interface but not with type for indexed property #19865

Closed
rdeneau opened this issue Nov 9, 2017 · 3 comments
Closed

Error with interface but not with type for indexed property #19865

rdeneau opened this issue Nov 9, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@rdeneau
Copy link

rdeneau commented Nov 9, 2017

TypeScript Version: 2.6.0

Code

interface I<K extends string, P> {
    [key in K]?: P; // Error: 1. A computed property name must directly refer to a built-in symbol.
                    //        2. A computed property name must be of type 'string', 'number', 'symbol' or 'any'.
}

type T<K extends string, P> = {
    [key in K]?: P; // No Errors !?
};

Expected behavior:
Same error for both definitions, I and T.

Actual behavior:
Error only with the interface.

@aluanhaddad
Copy link
Contributor

aluanhaddad commented Nov 9, 2017

This is essentially a duplicate of #18299

@mhegazy mhegazy added the Duplicate An existing issue was already created label Nov 9, 2017
@kreba
Copy link

kreba commented Nov 10, 2017

For other n00bs like me: Note that there is a difference between "indexed" and "mapped" types.
See http://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types

@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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

5 participants