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

Property definition alignment with es6 in class constructor #6549

Closed
Alphapage opened this issue Jan 20, 2016 · 7 comments
Closed

Property definition alignment with es6 in class constructor #6549

Alphapage opened this issue Jan 20, 2016 · 7 comments
Labels
Duplicate An existing issue was already created

Comments

@Alphapage
Copy link

Hello,

I didn't find a previous discussion about this subject.
Here is the code:

Class Test {
    private _test:string;
    public test:number;

    constructor() {
         this._test="";
         this.test=1;
         this.test2="";  // error: must be declared, but it should guess the typing is string and public
         this._test3 : string[]; // invalid for now: could be private string[]
         this.test4 : string[];  // invalid for now: could be public string[]
        private this.test5 : string[];  // invalid for now: could be public string[], but modified to private
     }
}

Do you plan to support such a feature ? I mean this._test3,this.test4 and this.test5
Are you working on this.test2 to add better intellisense for both ts and js (this.test2 shows any in vscode) ?

Thanks in advance for your answers.

@vladima vladima added the Duplicate An existing issue was already created label Jan 20, 2016
@vladima
Copy link
Contributor

vladima commented Jan 20, 2016

duplicate of #766

@vladima vladima closed this as completed Jan 20, 2016
@DanielRosenwasser
Copy link
Member

See also #4955.

@Alphapage
Copy link
Author

Ok you learn me something every time :-)

When I try this code from #4955:

class Alpha {
  constructor() {
    this.size = 42; //error
  }
}
var x = new Alpha();
var y = x.size; // y: number //error

I get the error: property 'size' does not exist on type 'Alpha'. Am I missing a tsconfig option ?
And when using js with tsserver (vscode), then size is of type any. But in the post, it seems to be supported. Do you have the same problem in vscode for js ?

@DanielRosenwasser
Copy link
Member

We haven't released that functionality just yet. I'm not sure if there's an easy way to enable it right now to experiment. @zhengbli might have a better idea.

@zhengbli
Copy link
Contributor

@Alphapage are you using the latest version of typescript compiler? I tested using typescript@next on npm, and I didn't get the errors, even in vscode. To be specific, the version I'm using is Version 1.8.0-dev.20160120

@Alphapage
Copy link
Author

Sorry, nothing changes in js and in ts too, I get same errors. No typings and property declaration is needed!

@Alphapage
Copy link
Author

I tried with Version 1.8.0-dev.20160122 without success. I will open a clean issue to report the problem:#6565

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants