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

Unexpected "in" error in esbuild but not Typescript playground #3033

Closed
breunigs opened this issue Apr 1, 2023 · 1 comment
Closed

Unexpected "in" error in esbuild but not Typescript playground #3033

breunigs opened this issue Apr 1, 2023 · 1 comment

Comments

@breunigs
Copy link

breunigs commented Apr 1, 2023

Using esbuild 0.17.14 to compile this snippet:

const LAYERS: { [keyof in "bar"]?: boolean } = {
    bar: true,
};

results in

✘ [ERROR] Unexpected "in"

    foo.ts:1:23:
      1 │ const LAYERS: { [keyof in "bar"]?: boolean } = {
        ╵                        ~~

1 error

whereas the TS playground seems not to mind:
https://www.typescriptlang.org/play?#code/MYewdgzgLgBAMgQQJoFEBKBlAXDA3jAbQGsBTATxADMYBLMGAIgCMBDAJwYF0B+HJkEABsSLegF8YAXjwAoGPJis2OKGwCuJADQyxAbhmhIQkgDpBIAOYAKRKkwBKIA

This approach is used here: https://github.com/maplibre/maplibre-gl-js/blob/3157c340e5573699e46ce4b3fc17e9e670442e1a/src/render/render_to_texture.ts#L13-L19 if a non-toy example is desired.

I am not familiar enough with the JS/TS ecosystem to judge what's wrong here, I am hoping you know.

@hyrious
Copy link

hyrious commented Apr 1, 2023

The keyof in this example is interpreted as a type name instead of a keyword. That is to say it is effectively the same as

const LAYERS: { [P in "bar"]?: boolean }

@evanw evanw closed this as completed in 9fbf1fd Apr 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants