Microsoft/TypeScript

Mixed-in classes with functions returning 'this' have TS2526 error in DTS file

Open

#52,687 建立於 2023年2月8日

在 GitHub 查看
 (1 留言) (2 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: Declaration EmitHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

Bug Report

🔎 Search Terms

TS2526 mixin declaration this

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

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)

貢獻者指南