-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
In JS, assignment to an undeclared instance property should act as its declaration #22896
Comments
Note that this is about checking |
I think it's a correct error, because it's an instance variable.
|
@Kovensky Not sure what design goals of Salsa is but |
To be honest, I think adding properties to instances after the fact isn't something we can do under our current design. |
What's being proposed? Would a set of a property on a class instance never be an error? That seems like going too far. |
At least in Webpack they are fine with initiating the member with undefined in constructor. See this comment: webpack/webpack#6869 (comment) |
I think a solution here is to support similar to #15715. |
A class C {
constructor() {
this.upfront = 1
// here?: this.late = undefined
}
}
var c = new C();
// here?: /** @property */
c.late = 2; Of the two, The only reason I can think of to prefer One place where function C(full = true) {
this.basics = 'just the basics'
if (full) initC(this)
}
function initC(c) {
c.other = 'stuff goes here'
c.db = somedb.connect()
c.launchMissiles = function() { /* CLASSIFIED but definitely IRREVOCABLE */ }
}
C.prototype.afterInitialisation = function() {
// refer multiple times to c.other, c.db, c.launchMissiles
} Since /** @param {C} c */
function initC(c) {
/** @property */
c.other = 'stuff goes here'
/** @property */
c.db = somedb.connect()
/** @property */
c.launchMissiles = function() { /* CLASSIFIED but definitely IRREVOCABLE */ }
} Even in this scenario, the duplication in the constructor might be just as good as the additional doc comments in My vote is to look for some other motivating example than webpack, since it looks like the webpack changes just required one or two additions per class. Plus, those additions are good for the runtime performance of webpack. |
I was thinking of adding it on the class/function declaration, e.g.: /**
* @property {number} a
*/
class C {
m() {
this.a;
}
} or /**
* @class
* @property {number} a
*/
function F() {
this.m = function m () {
this.a;
}
} |
TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms:
Salsa, Class member, instance
TypeScript Version
2.7.2
Code
Expected behavior:
No error
Actual behavior:
The text was updated successfully, but these errors were encountered: