microsoft / microsoft/TypeScript

Can't extend mixin constructor that constructs a generic type

オープン
#13,807 コメント 6 件 リアクション 13 件 担当者 0 名 GitHub で見る

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

In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

This applies regardless of whether or not I intersect it with some bogus type, or have a reasonable constraint. So none of the following works.

Returning a plain T

export type Constructor<T> = new (...args: any[]) => T

export interface Timestamp {
    timestamp: Date;
}

// plain old T
export function Timestamp<T, CT extends Constructor<T>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
    return class extends Base {
        timestamp = new Date();
    }
}

Constructor of T with a bogus object type ({})

export type Constructor<T> = new (...args: any[]) => T

export interface Timestamp {
    timestamp: Date;
}

// Constructor of T with a bogus object type
export function Timestamp<T, CT extends Constructor<T & {}>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
    return class extends Base {
        timestamp = new Date();
    }
}

Constructor of T where T is constrained to {}

export type Constructor<T> = new (...args: any[]) => T

export interface Timestamp {
    timestamp: Date;
}

export function Timestamp<T extends {}, CT extends Constructor<T>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
    return class extends Base {
        timestamp = new Date();
    }
}

Constructor of T where T is constrained to object (see also #13805)

export type Constructor<T> = new (...args: any[]) => T

export interface Timestamp {
    timestamp: Date;
}

export function Timestamp<T extends object, CT extends Constructor<T>>(Base: CT): Constructor<Timestamp> & Constructor<T> {
    return class extends Base {
        timestamp = new Date();
    }
}

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

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

はじめの一歩

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

調査の方向性

まず、issue にある 4 つの汎用コンストラクターと mixin の例を再現し、その結果生じる型チェックエラーを調べます。コンパイラーによる汎用コンストラクターシグネチャとクラス式の処理を追跡します。指定された戻り値の型で、意図した汎用 mixin コンストラクターパターンが受け入れられ、無関係なチェックを弱めないことが完了の条件です。

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

評価

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

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

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