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

script setup + const enum = 💔 #277

Closed
jods4 opened this issue Jun 21, 2021 · 5 comments
Closed

script setup + const enum = 💔 #277

jods4 opened this issue Jun 21, 2021 · 5 comments
Labels
wontfix This will not be worked on

Comments

@jods4
Copy link

jods4 commented Jun 21, 2021

Even when everything is correct and runs properly, Volar complains about imported const enums.
image

This problem can be worked around a little by using import type, but depending on your code you get another error then:
image

I know the default Vite setup can't properly compile const enums, but we use a custom build with regular TSC that compiles const enums efficiently. This is important for us because we have tons of enums generated from server-side code and it really adds up.

@johnsoncodehk johnsoncodehk added the enhancement New feature or request label Jun 22, 2021
@johnsoncodehk
Copy link
Member

Thanks for the report. But we can't change this behavior, otherwise it will be a bug for general users, because users will get runtime error in this case.

You can use import type + @ts-ignore to bypass the problem.

import type { X } from "./enum";

const map = {
  // @ts-ignore
  [X.A]: 1
}

@johnsoncodehk johnsoncodehk added wontfix This will not be worked on and removed enhancement New feature or request labels Jun 30, 2021
@jods4
Copy link
Author

jods4 commented Jul 1, 2021

@johnsoncodehk could you please explain what runtime error general (who?) users would get? I am not sure I get it.

@jods4
Copy link
Author

jods4 commented Jul 1, 2021

I want to add that I'm having similar error messages when importing types.

These can be work-around by using import type explicitly but it's inconvenient to have to split imports in two, that creates lots of imports quickly.

// Error: 'Type' only refers to a type, but is being used as a value here.ts(2693)
import { Type, Value } from "x";

// Work-around: double imports
import { Value } from "x";
import type { Type } from "x";

Also: when you migrate from a regular <script> to <script setup> these are all things that one needs to change. It'd be nice if it just worked.

@johnsoncodehk
Copy link
Member

See #209 (comment).

@jods4
Copy link
Author

jods4 commented Jul 2, 2021

I went down the linked issues to vuejs/core#3183 which seems to be the open issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants