[7.1 Regression] Unexpected behaviour change from Stronger Distributive Type checks
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
🔎 Search Terms
7.1 regression, TS2345
🕗 Version & Regression Information
- This changed between versions 7.0.2 and 7.1.0-beta
⏯ Playground Link
💻 Code
export class C {
m1<T>(
item: T,
callback: T extends string
? (item: T) => void
: (item: T) => void
): void {
callback(item);
callback(item as T extends string ? T : T);
}
m2(
item: string,
callback?: (item: string) => void
): void;
m2<T>(
item: T,
callback: (item: T) => void
): void;
m2<T>(
item: T,
callback: T extends string
? ((item: T) => void) | undefined
: (item: T) => void
): void {
if (callback) {
callback(item);
callback(item as T extends string ? T : T);
}
}
}
🙁 Actual behavior
src/main.ts:8:18 - error TS2345: Argument of type 'T' is not assignable to parameter of type 'T'.
'T' is only assignable to the non-distributed 'T', but 'T' has been distributed here.
8 callback(item);
~~~~
src/main.ts:27:22 - error TS2345: Argument of type 'T' is not assignable to parameter of type 'T'.
'T' is only assignable to the non-distributed 'T', but 'T' has been distributed here.
27 callback(item);
🙂 Expected behavior
No Error.
Additional information about the issue
In case of m1, if tsc is aiming to strengthen Distributive Type checks, I would hope tsc can be smart enough to "undistribute" type whenever it hits some identical declarations on different branches. As for how to define identical, I suppose it may deserve further thinkings and discussions.
For m2, we have a common way of writing overload in typescript. The condition T extends string is there for determining if a method argument is optional or not. The (strengthened) disributive check that follows is kinda unintended & unwanted effect in this case. It would be weird to let the ? T : T trick to become a part of usual type overload maintenance.
I am treating the stronger checks as regression, since it actually brings undesired behaviour changes as presented above.
- 主要言語
- Go
- スター
- 112k
- フォーク
- 15.4k
- 平均マージ
- 3日 6時間
- マージ済み PR(30日)
- 136
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/TypeScript のほかの issue
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file locationオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/TypeScript#65087 ·
メンテナーはふだん 1 日以内に返信
-
API: `tsc.exe` opens a visible console window on Windows when the parent process has no consoleオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
microsoft/TypeScript#65083 ·
メンテナーはふだん 1 日以内に返信
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
microsoft/TypeScript#64758 ·
メンテナーはふだん 1 日以内に返信
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`対応中かも @rajnish-verma-22172 が 12 日前に担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microsoft/TypeScript#64742 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindings対応中かも @dmety が 25 日前に担当しました。 オープンBug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/TypeScript#64661 ·
メンテナーはふだん 1 日以内に返信
microsoft/TypeScript の issue をすべて見る
似ている issue
-
date_time, url_encode, html_escape, to_unix_time, contains_all and contains_any panic when called without arguments対応中かも @antcybersec が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
projectdiscovery/dsl#372 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
JuliusBrussee/caveman#1449 ·
メンテナーはふだん 1 日以内に返信
-
clawsweeper:fix-shape-clear clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
openclaw/gogcli#1291 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/arrow-swift#209 ·
メンテナーはふだん 1 日以内に返信
-
bug(instrumentation/kafka-go): producer hook writes trace headers into the caller's messages対応中かも @Aryanbhargava18 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
open-telemetry/opentelemetry-go-compile-instrumentation#1669 ·
メンテナーはふだん 2 日以内に返信