in object literal methods inside an object literal with a type annotation. Note that this does not change: 1. The type of `this` in object literal methods. 2. The fact that this-property assignments are still declarations. They just don't block contextual typing like most declarations do. This change is a bit expensive. It first calls getThisContainer, which walks the tree upward. Then it calls checkThisExpression, which will usually call getContextualType on the object literal method. If the new code then returns true, it will proceed to redo much of that work. Calling checkThisExpression should not cause incorrect circularity failures; we only have to inspect the shape of the object literal and not the types of its properties to determine its type.
20 lines
372 B
TypeScript
20 lines
372 B
TypeScript
// @noEmit: true
|
|
// @allowJs: true
|
|
// @checkJs: true
|
|
// @strict: true
|
|
// @Filename: bug25926.js
|
|
|
|
/** @type {{ a(): void; b?(n: number): number; }} */
|
|
const o1 = {
|
|
a() {
|
|
this.b = n => n;
|
|
}
|
|
};
|
|
|
|
/** @type {{ d(): void; e?(n: number): number; f?(n: number): number; g?: number }} */
|
|
const o2 = {
|
|
d() {
|
|
this.e = this.f = m => this.g || m;
|
|
}
|
|
};
|
|
|