-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Open
Labels
Domain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolutionHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
π Search Terms
function, argument, parameter, generic, callback, infer
π Version & Regression Information
By trying out different versions in Playground, it looks like it works correctly in version 4.7.4 and lower
β― Playground Link
π» Code
declare function call<T>(fn: (a: string, b: T) => unknown): (b: T) => unknown;
declare function fn<Args extends any[]>(
fn: (...args: Args) => unknown,
): (...args: Args) => unknown;
const result = call(fn(function (a, b: number) {}));π Actual behavior
The a parameter's type is any.
π Expected behavior
The a paramater's type should be string
Additional information about the issue
I encountered this while trying to create a helper function in a codebase that uses Effect:
import { Effect } from "effect"
function call<A, E, R, T = void>(fn: (a: string, b: T) => Effect.Effect<A, E, R>) {
return (b: T) => fn("value", b)
}
const fnA = call((a, b: number) => // a is `string`
Effect.gen(function* () {
return yield* Effect.succeed(`${a}: ${b}`)
}),
)
const fnB = call(
Effect.fn(function* (a, b: number) { // a is `any`?
return yield* Effect.succeed(`${a}: ${b}`)
}),
)Metadata
Metadata
Assignees
Labels
Domain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionRelated to type inference performed during signature resolution or `infer` type resolutionHelp WantedYou can do thisYou can do thisPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases