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

Bad error message for type used as index #25770

Closed
ghost opened this issue Jul 18, 2018 · 3 comments · Fixed by #39973 or #40226
Closed

Bad error message for type used as index #25770

ghost opened this issue Jul 18, 2018 · 3 comments · Fixed by #39973 or #40226
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Domain: Mapped Types The issue relates to mapped types Help Wanted You can do this

Comments

@ghost
Copy link

ghost commented Jul 18, 2018

TypeScript Version: 3.1.0-dev.20180717

Code

type S = "a" | "b";
type O = { [S]: number };

Expected behavior:

Error message telling me to use K in S.

Actual behavior:

src/a.ts:2:13 - error TS2693: 'S' only refers to a type, but is being used as a value here.

@ghost ghost added Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Domain: Mapped Types The issue relates to mapped types labels Jul 18, 2018
@mhegazy mhegazy added this to the Community milestone Jul 18, 2018
@mhegazy mhegazy added the Help Wanted You can do this label Jul 18, 2018
@a-tarasyuk
Copy link
Contributor

@mhegazy @andy-ms @DanielRosenwasser which message will be acceptable to this case?

@ghost
Copy link
Author

ghost commented Jul 18, 2018

I'm thinking something like:
'S' is a type, not a symbol. To use 'S' as a key type of a mapped type, use 'K in S'.

(Note that with const S = Symbol(); the code would compile as-is.)
Note that a mapped type will only work here if the type does not have any other properties; see #24286.
We could also add a codefix triggered by this diagnostic.

@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

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 Domain: Mapped Types The issue relates to mapped types Help Wanted You can do this
Projects
None yet
4 participants