microsoft / microsoft/TypeScript
Instantiable types from return types of contextual signatures don't provide contextual type information for return expressions
オープン
まだ誰も着手していません。
Domain: check: Contextual Types
Help Wanted
Possible Improvement
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
instantiable contextual signature return types
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
type ContextStates =
| {
status: "loading";
data: null;
}
| {
status: "success";
data: string;
};
declare function createStore<TContext>(
context: TContext,
config: {
on: Record<string, (ctx: TContext) => TContext>;
},
): void;
const store = createStore(
{
status: "loading",
data: null,
} as ContextStates,
{
on: {
fetch: () => ({
status: "success",
data: "hello",
}),
},
},
);
🙁 Actual behavior
status: "success", errors
🙂 Expected behavior
no error
Additional information about the issue
Making (ctx: TContext) => TContext into a type parameter makes it work (see TS playground) but that's not natural to write and isn't broadly applicable as a workaround
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされた TypeScript Playground の再現コードを実行し、提供されているジェネリック型の回避策と比較してください。コンテキスト付きシグネチャの return 式が拒否される理由を調査し、回避策なしで元の例が型チェックに通れば、issue は完了とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100