-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
.d.ts emitted from JS doesn't use this
for method return types
#53051
Comments
The TypeScript example includes export declare class Controller {
constructor();
updateDisplay(): this;
}
export declare class BooleanControllerNoExtraMember extends Controller {
constructor();
updateDisplay(): this;
}
export declare class BooleanControllerWithExtraMember extends Controller {
test: number;
constructor();
updateDisplay(): this;
} |
This is when creating type declarations from JavaScript (you can change language in the TSConfig > Lang option). |
I think the output should match whatever TS does; the current state is clearly inconsistent. |
Here's a repro that's the same code in JS and TS, but generates different .d.ts files: export class C {
updateDisplay() {
return this;
}
} In C, |
this
for methods
this
for methodsthis
for methods
this
for methodsthis
for method return types
Here's a repro for the overrride part of the bug (though this should perhaps be a separate bug): export class C {
updateDisplay() {
}
}
export class D extends C {
updateDisplay() {
}
} The generated d.ts for JS has |
Filed #54061 to track the missing-identical-override bug |
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
NOTE: This is JS, not TS.
π Actual behavior
The resulting declaration file includes
updateDisplay()
inBooleanControllerWithExtraMember
with a return type ofBooleanControllerWithExtraMember
. This is problematic and causes type errors because the return type forBooleanControllerWithExtraMember.updateDisplay()
needs to be assignable tothis
. Duplicating the JSDoc to specify that it returnsthis
is undesirable since we don't want to have to duplicate the JSDoc for all derived classes.I included
BooleanControllerNoExtraMember
as well to highlight the inconsistency that it sometimes doesn't specify the method overload due to seemingly unrelated changes to the class.π Expected behavior
BooleanControllerWithExtraMember
doesn't specifyupdateDisplay()
because it doesn't need to. This is how TypeScript 4.5 behaves.The text was updated successfully, but these errors were encountered: