-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Expressions in JS special assignments don't use jsdoc for contextual type #25571
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
Comments
looks like the contextual type is not picked up correctly for the special property assignment case. |
I'm going to make a partial fix that makes these assignments appropriately context sensitive, which fixes this bug, but then work on a permanent fix that makes the type of other assignments, like /** @type {{ status: 'done' }} */
F.prototype = { status: 'done' } correctly assign |
Explicitly typed special assignments should be context sensitive if they have an explicit type tag. Previously no special assignments were context sensitive because they are declarations, and in the common, untyped, case we inspect the right side of the assignment to get the type of the left side, and inspect the right side of the assignment to get the type of the left side, etc etc. Note that some special assignments still return `any` from checkExpression, so still don't get the right type. Fixes #25571
* Explicitly typed js assignments: context sensitive Explicitly typed special assignments should be context sensitive if they have an explicit type tag. Previously no special assignments were context sensitive because they are declarations, and in the common, untyped, case we inspect the right side of the assignment to get the type of the left side, and inspect the right side of the assignment to get the type of the left side, etc etc. Note that some special assignments still return `any` from checkExpression, so still don't get the right type. Fixes #25571 * Change prototype property handling+update bselines * Fix indentation in test * Update baselines
@sandersn is this the best way of asserting member types? i.e. the one thing I wasn't sure of was should I be using some On my reading of jsdoc docs it seems using |
In Javascript, the pattern that the compiler expects is modelled on Closure: class C {
/** @param {number} x */
constructor(x) {
this.x = x;
/** @type {number | undefined} */
this.y;
}
} Basically it's just looking for assignments to method() {
this.z = 'hi' // z: string | undefined
} We have a proposal for a |
TypeScript Version: 3.0.0-dev.20180710
Search Terms: tagged discriminated union property this jsdoc checkjs allowjs literal
The following typescript works great:
However, the equivalent JS does not:
Both assignments give the error:
Expected behavior:
JS behaves the same as TS version
The text was updated successfully, but these errors were encountered: