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

useDefineForClassFields flag for different output #35563

Closed
agrozyme opened this issue Dec 7, 2019 · 3 comments
Closed

useDefineForClassFields flag for different output #35563

agrozyme opened this issue Dec 7, 2019 · 3 comments
Labels
Unactionable There isn't something we can do with this issue

Comments

@agrozyme
Copy link

agrozyme commented Dec 7, 2019

TypeScript Version: 3.7.3

Search Terms: useDefineForClassFields

Code
See this small repo
Base Class

after clone the repo and npm i , run npm test
then change "useDefineForClassFields": true in tsconfig.json and run npm test again

Expected behavior:
useDefineForClassFields = false

Y { xf: 'FALSE', xfr: 'FALSE', xa: 'TRUE', ef: 'ey', efr: 'ey' }

Actual behavior:
useDefineForClassFields = true

Y {
  xf: undefined,
  xfr: undefined,
  xa: undefined,
  ef: 'ey',
  efr: 'ey' }

Playground Link:

Related Issues: #33509

@RyanCavanaugh RyanCavanaugh added the Unactionable There isn't something we can do with this issue label Dec 20, 2019
@RyanCavanaugh
Copy link
Member

Please post a self-contained repro here; we cannot run commands off arbitrary repos to demonstrate these sorts of bugs.

@agrozyme
Copy link
Author

agrozyme commented Dec 22, 2019

I clone the repo from GitLab to GitHub
Base Class

Here are the screen captures.

00
01
02

@agrozyme
Copy link
Author

I find the solution, use declare keyword.

  abstract class X extends Base implements YI {
    declare xa: string;
    declare xf: string;
    declare xfr: string;

    protected ef: string = 'ex';
    protected readonly efr: string = 'ex';

    protected get ea() {
      return 'ex';
    }

    static z() {
      return 'X';
    }

    type() {
      return X;
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unactionable There isn't something we can do with this issue
Projects
None yet
Development

No branches or pull requests

2 participants