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

Mapped properties in interfaces have undefined behavior #18299

Closed
dead-claudia opened this issue Sep 7, 2017 · 0 comments · Fixed by #46346
Closed

Mapped properties in interfaces have undefined behavior #18299

dead-claudia opened this issue Sep 7, 2017 · 0 comments · Fixed by #46346
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fix Available A PR has been opened for this issue Help Wanted You can do this
Milestone

Comments

@dead-claudia
Copy link

TypeScript Version: Playground version

Code

Linked playground

type Foo = {
    [P in 'a' | 'b']: any;
}

interface Bar {
    [P in 'a' | 'b']: any;
}

Expected behavior:

One of these two options:

  1. No errors at all, and roughly equivalent semantics.
  2. A parse error, in case this should specifically be disallowed (to align with classes, since [foo in bar] is required to be a valid class property/method name).

Actual behavior:

A mess of type errors because [P in T]: any is parsed in interfaces as a computed symbol property with key P in T (i.e. a boolean). In kind, I get three sets of type errors:

  1. For P:

    • A computed property name in an interface must directly refer to a built-in symbol.
    • Cannot find name 'P'.
    • The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
  2. For 'a' | 'b':

    • A computed property name in an interface must directly refer to a built-in symbol.
    • The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter.
    • The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants