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

tsconfig useDefineForClassFields setting not respected #3227

Closed
molszews opened this issue Apr 30, 2021 · 4 comments · Fixed by #4279
Closed

tsconfig useDefineForClassFields setting not respected #3227

molszews opened this issue Apr 30, 2021 · 4 comments · Fixed by #4279
Assignees
Labels
inconsistency Inconsistency between dev & build p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@molszews
Copy link

Describe the bug

My project requires use of setting useDefineForClassFields: true in tsconfig.json. For some reason the output presented by npm run dev behaves like that setting was set to false.

Reproduction

Create from React-TypeScript template (npm init @vitejs/app my-app -- --template react-ts) and add following code to App.tsx

class ContactInfoDto {
    firstName; lastName;
}

and inside App():

const contactInfo = new ContactInfoDto();
Object.keys(contactInfo).forEach(k => console.log(k));

It should console.log two lines when useDefineForClassFields set to true in tsconfig.json. (It works that way executed under webpack+babel or webpack+esbuild)

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

npx: installed 1 in 0.738s

  System:
    OS: Linux 5.4 elementary OS 5.1.7 Hera
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
    Memory: 4.45 GB / 31.16 GB
    Container: Yes
    Shell: 4.4.20 - /bin/bash
  Binaries:
    Node: 12.21.0 - ~/.nvm/versions/node/v12.21.0/bin/node
    Yarn: 1.22.10 - /usr/bin/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v12.21.0/bin/npm
  Browsers:
    Chrome: 90.0.4430.85
    Firefox: 87.0
  npmPackages:
    vite: ^2.2.3 => 2.2.3 

Used package manager: npm

@Obiwarn
Copy link

Obiwarn commented May 3, 2021

Same here. This also seems to break some MobX functionality .

@haoqunjiang haoqunjiang added bug p4-important Violate documented behavior or significantly improves performance (priority) and removed pending triage labels May 7, 2021
@haoqunjiang
Copy link
Member

According to ESBuild documentation, the transform API does not access the file system, so it can't automatically discover the tsconfig.json. Vite needs to pass the tsconfigRaw option explicitly to it.

@haoqunjiang
Copy link
Member

On the other hand, I think this API design in ESBuild is quite confusing.

Why does it accept a path string in the sourcefile option but still refuse to access other part of the file system to get the corresponding tsconfig.json?

@haoqunjiang
Copy link
Member

haoqunjiang commented Jul 2, 2021

A note: in TypeScript 4.3, target: 'esnext' now indicates useDefineForClassFields: true.
microsoft/TypeScript#42663

@haoqunjiang haoqunjiang self-assigned this Jul 2, 2021
@haoqunjiang haoqunjiang added the inconsistency Inconsistency between dev & build label Jul 2, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
inconsistency Inconsistency between dev & build p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants