microsoft / microsoft/TypeScript
Generic type can't be assigned to the same DeepReadonly type
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Assigning generic type T to it's deep readonly DeepReadonly<T> cause error however shallow Readonly<T> works fine. Also I found that known types do work well with DeepReadonly .
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
DeepReadonly assign return generic nested readonly
Code
// Simple deep readonly
export type DRO<T> = { readonly [P in keyof T]: DR<T[P]> };
type DR<T> = T extends object ? DRO<T> : T;
// Sample type
interface TMP {
a: number;
b: {
c: boolean;
};
}
// Works fine
const a: TMP = { a: 10, b: { c: false } };
const b: DRO<TMP> = a;
// Doesn't work
class X<T> {
constructor(private readonly t: T) {}
foo(): DRO<T> {
// Error here
return this.t;
}
bar(): Readonly<T> {
// Works fine
return this.t;
}
}
Expected behavior:
Method foo shouldn't have error
Actual behavior:
Error: Type 'T' is not assignable to type 'DRO'.
Related Issues:
Maybe: #12826 and #21919
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
TypeScript Playground での再現から始め、参照されている TypeScript バージョンまたは現在のビルドと動作を比較してください。T から DRO へのジェネリックな代入を、動作している具体的なケースおよび Readonly のケースと併せて調査してください。既存のケースをリグレッションさせることなく、報告されたジェネリックな foo メソッドで指定されたエラーが発生しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100