microsoft / microsoft/TypeScript

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

オープン
#52,687 コメント 1 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: Declaration Emit Help Wanted
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

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)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた TypeScript Playground の再現コードから始め、正しい TS ソースと、それから出力された DTS を比較します。ミックスインされたクラスとその setScale メソッドの宣言出力を追跡します。再現したソースから TS2526 エラーなしで DTS ファイルが出力されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。