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

Typescript const enums not compiled correctly #3376

Closed
jestarray opened this issue Jan 28, 2019 · 3 comments
Closed

Typescript const enums not compiled correctly #3376

jestarray opened this issue Jan 28, 2019 · 3 comments

Comments

@jestarray
Copy link

jestarray commented Jan 28, 2019

Version

3.3.0

Reproduction link

https://github.com/jestarray/const-enum-vue

Environment info

   @vue/babel-helper-vue-jsx-merge-props:  1.0.0-beta.2
    @vue/babel-plugin-transform-vue-jsx:  1.0.0-beta.2
    @vue/babel-preset-app:  3.3.0
    @vue/babel-preset-jsx:  1.0.0-beta.2
    @vue/babel-sugar-functional-vue:  1.0.0-beta.2
    @vue/babel-sugar-inject-h:  1.0.0-beta.2
    @vue/babel-sugar-v-model:  1.0.0-beta.2
    @vue/babel-sugar-v-on:  1.0.0-beta.2
    @vue/cli-overlay:  3.3.0
    @vue/cli-plugin-babel: ^3.3.0 => 3.3.0
    @vue/cli-plugin-typescript: ^3.3.0 => 3.3.0
    @vue/cli-service: ^3.3.0 => 3.3.1
    @vue/cli-shared-utils:  3.3.0
    @vue/component-compiler-utils:  2.5.1
    @vue/preload-webpack-plugin:  1.1.0
    @vue/web-component-wrapper:  1.2.0
    babel-helper-vue-jsx-merge-props:  2.0.3
    babel-plugin-transform-vue-jsx:  4.0.1
    vue: ^2.5.21 => 2.5.22
    vue-class-component: ^6.0.0 => 6.3.2
    vue-hot-reload-api:  2.3.1
    vue-loader:  15.6.2
    vue-property-decorator: ^7.0.0 => 7.3.0
    vue-style-loader:  4.1.2
    vue-template-compiler: ^2.5.21 => 2.5.22
    vue-template-es2015-compiler:  1.8.2
  npmGlobalPackages:
    @vue/cli: 3.3.0

Steps to reproduce

-npm install the dependencies,
-npm run build
-check the output in dist

What is expected?

const enum declarations should be inlined.
example:

const enum TEST{
HELLLO
}

console.log(TEST.HELLO);
//should be transpiled to console.log(0)

What is actually happening?

It's transpiled into console.log(TEST.HELLO) instead.


I have a const enum of keyboard events and event key names that I need inlined correctly. Followed some solutions of ts-loader since vue cli uses it under the hood but no luck.

@jestarray
Copy link
Author

microsoft/TypeScript#10879 (comment)

Alright, managed to fix , this had to be added to tsconfig :
"isolatedModules": false /* Transpile each file as a separate module (similar to 'ts.transpileModule').
question remains if you guys want it as default for tsconfig. Otherwise, feel free to close.

@yoyo930021
Copy link
Member

@ryannmedina
Copy link

Hi @jestarray! I ran into a similar issue this last week and this thread was helpful.

We ended up separating our enum "types" into a different file. (a plain .ts file) Then we imported that file into our types file. It fixed the problem. Here's a watered down version:

types.d.ts

// Import Enums
import { MyEnum } from './enums'

export interface MyInterface {
   firstProperty: MyEnum,
   secondProperty: string,
   thirdProperty: number 
}

enums.ts

export enum MyEnum {
   firstProperty = 0,
   secondProperty = 1,
   thirdProperty = 2 
}

That was suggested by Lukas Behal.

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

3 participants