Open
Description
π Search Terms
type parameters generic conextual parameter types context sensitive
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
export declare const fn: <T, Args extends Array<any>, Ret>(
self: T,
body: (this: T, ...args: Args) => Generator<any, Ret, never>
) => (...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: 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: N) => void
), it makes sense to assign contextual parameter types.