microsoft / microsoft/TypeScript
Mixed-in classes with functions returning 'this' have TS2526 error in DTS file
Open
Nobody has claimed this yet.
Bug
Domain: Declaration Emit
Help Wanted
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
TS2526 mixin declaration this
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
class Sprite {
name = "";
constructor(name: string) {
this.name = name;
}
}
type Constructor = new (...args: any[]) => {};
function Scale<TBase extends Constructor>(Base: TBase) {
return class Scaling extends Base {
_scale = 1;
setScale(scale: number): this {
this._scale = scale;
return this;
}
};
}
export const A = Scale(Sprite);
DTS:
declare class Sprite {
name: string;
constructor(name: string);
}
export declare const A: {
new (...args: any[]): {
_scale: number;
// A 'this' type is available only in a non-static member of a class or interface.ts(2526)
setScale(scale: number): this;
};
} & typeof Sprite;
export {};
🙁 Actual behavior
TS2526 error appears in emitted dts file
🙂 Expected behavior
No error (TS files that have no errors should not emit DTS file with errors)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked TypeScript Playground reproduction and compare the valid TS source with its emitted DTS output. Trace declaration emission for the mixed-in class and its setScale method. Done means the reproduced source emits a DTS file without the TS2526 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100