7.1: destructured parameter with a `= {}` default loses its contextual type (TS7031)
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 53/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- compilers
調査の方向性
Start by reading the compiler’s contextual parameter typing and destructuring code, then use the issue’s minimal reproduction to compare behavior across the affected 7.1 and working 7.0.2 versions. Add a regression test covering an optional contextually typed parameter with a destructuring pattern and an = {} default; done means both binding elements retain their contextual types without TS7031, while the two control cases still pass.
索引モデルが issue の本文から書いたものです。
説明
🔎 Search Terms
TS7031, binding element implicitly has an any type, destructuring parameter default, contextual type, 7.1 regression
🕗 Version & Regression Information
- This changed between versions 7.0.2 and 7.1.0-beta
- Still present in 7.1.0-dev.20261026.1
- 6.0.3 and 7.0.2 report no errors
⏯ Playground Link
No response
💻 Code
// tsconfig: { "compilerOptions": { "strict": true, "noEmit": true, "skipLibCheck": true, "types": [] } }
type Fn = (input?: { channel?: string; minutes?: number }) => number;
export const f: Fn = ({ channel, minutes } = {}) => (channel ? 1 : 0) + (minutes ?? 0);
The error needs all three of: a destructuring pattern, an = {} initializer, and a contextually typed optional parameter. Each of these alone still checks cleanly on 7.1:
type F2 = (input: { channel?: string; minutes?: number }) => number;
export const f2: F2 = ({ channel, minutes }) => (channel ? 1 : 0) + (minutes ?? 0); // no initializer: OK
type G = (input?: { channel?: string }) => number;
export const g: G = (input = {}) => (input.channel ? 1 : 0); // identifier, not a pattern: OK
🙁 Actual behavior
a.ts(2,25): error TS7031: Binding element 'channel' implicitly has an 'any' type.
a.ts(2,34): error TS7031: Binding element 'minutes' implicitly has an 'any' type.
🙂 Expected behavior
No errors: channel and minutes take their types (string | undefined, number | undefined) from the contextual parameter type, as on 6.0.3 and 7.0.2.
Additional information about the issue
Found while trialling 7.1.0-beta on a large monorepo; it fires in test helpers and callbacks typed through an alias (({ a, b } = {}) => … assigned to a function type with an optional object parameter).
- 主要言語
- Go
- スター
- 112k
- フォーク
- 16k
- 平均マージ
- 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
-
orchestrator: NFS-cache "cache path is not set" WARN logged on every build/launch instead of onceオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 65/100
influxdata/telegraf#20031 ·
メンテナーはふだん 1 日以内に返信
-
pkg/registry/file no longer builds for GOOS=windows: unguarded syscall.Stat_t in qualified_resource_migration.go対応中かも @AnshulPatil2005 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
OneBusAway/maglev#1914 ·
メンテナーはふだん 2 日以内に返信
-
[Bug] The Router doesn't log why it refused a request対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug needs-acceptance wg/data-plane-networking
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
vllm-project/semantic-router#5680 ·
メンテナーはふだん 2 日以内に返信