Type alias RemoveLastOptionalParam<Fn>

RemoveLastOptionalParam<Fn>: Fn extends ((...params) => infer R)
    ? ((...params) => R)
    : Fn

Type Parameters

  • Fn extends AnyFunction

Remarks

The following are note for the implementation.

Parameters and ReturnType types will work fine IF Fn is a concrete type. If Fn is not concrete (passed in as a type parameter), the Parameters and ReturnType could not be properly inferred.

For example, the following code failed to inferred the type of the variable x

type A = {
a: () => number;
};
function k<C extends A>() {
type t = ReturnType<C['a']>;
const x: t = 123;
return x;
}

Even though we know then signature of A['a'], we actually does not know the signature of C['a']. Considered the following type:

type B = A & {
a: (y: string) => string;
};
console.log(k<B>());

B is totally a valid subtype of A, and can even be used with the function k. We can concluded that ReturnType is not concrete enough.

Using infer, we can get both parameters type and the return type, as they come in pair. Parameters and ReturnType, on the other hand, are not.

Generated using TypeDoc