microsoft / microsoft/TypeScript
Parameters in functions with type parameters are not contextually-typed
@ahejlsberg がすでに取り組んでいます。
2025年6月4日 から。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
### 🔎 Search Terms
type parameters generic conextual parameter types context sensitive
### 🕗 Version & Regression Information
- This is the behavior in every version I tried
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250601#code/KYDwDg9gTgLgBAE2AYwDYEMrDsiA7AZ3gDM8AuOAHgBUAaOAQSgHMC5QZg8E2mp0AnpXR4BAPnoAlYDDEAKALAAoOHALBUxCnWWqARhAQCKcmAAsAlgW30AdPcysKTVgEo4AXjFwA4l2D8MNDColIy9HjAAG4BYsruXnBy9raO1owsBAne0jDKyqCQsDj4RHAQANaecKRyAN5wALbABATozMAUAETEEBBdcAC+9MQArnjIMBb4AFRy5HB4o416Ae51uiWEEKjAtqgQzKaWBLbNre3AEa7KgzdKBeDQ8LiE8HgQ1bUN520d3b1+kMRuNJtM8DNKAA5eQLKHrTavAg7PYHI7mKxnFp-K6Le53ZRAA
### 💻 Code
```ts
export declare const fn: , Ret>(
self: T,
body: (this: T, ...args: Args) => Generator
) => (...args: Args) => Ret
export const ok = fn({ message: "foo" }, function*(n: number) {
console.log(this.message, n) // ok
})
export const no = fn({ message: "foo" }, function*(n: N) {
console.log(this.message, n) // error
})
```
### 🙁 Actual behavior
The second case errors
### 🙂 Expected behavior
Both of those should work fine
### Additional information about the issue
Given TS is able (at times) to infer new generic signatures based on generic function arguments (notice the return type of the failing case: `const no: (n: N) => void`), it makes sense to assign contextual parameter types.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
評価
この issue はまだ評価されていません。