You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Alpha {
constructor() {
this.size = 42; //error : but it should be public of type number because no declaration
}
}
var x = new Alpha();
var y = x.size; // y: number //error
I get the error: property 'size' does not exist on type 'Alpha'.
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 ? Is this feature not implemented yet ?
Thanks in advance for your help.
The text was updated successfully, but these errors were encountered:
Alphapage
changed the title
Property without declaration: javascript alignment
Property without declaration: es6 alignment in constructor class
Jan 22, 2016
Alphapage
changed the title
Property without declaration: es6 alignment in constructor class
Property without declaration: es6 alignment in class constructor
Jan 22, 2016
This is not supported in TypeScript. All property declarations need to be declared before used in the constructor. see more details about a similar proposal that was declined in #766. The rational is that property declarations provide clear declaration of intent to the compiler, and the compiler can then provide more help. implicitly inferring declarations from constructors will miss typos in assignment to constructor properties, can not be generalized to all methods, and accessors, and will lead to inconsistent class declarations.
Issue #4955, is for .js files and not .ts files. Since a JS (ES2015/ES6) class does not have a concept of property declaration (yet), the compiler needs to infere from the JS class body. this only works in JS files when passing the --allowJS. see #4792 for more information.
Hello,
When I try this code from #4955:
I get the error: property 'size' does not exist on type 'Alpha'.
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 ? Is this feature not implemented yet ?
Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: