Suggestion
π Search Terms
strict Parameters<T>
associated ReturnType<T>
curry function
β
Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Given
type MP2 = {
a1: "a2";
b1: "b2";
};
type MP3 = {
a1: "a3";
b1: "b3";
};
type MR = {
a1: "ar";
b1: "br";
};
function foo<K extends keyof MP2>(p1: K, p2: MP2[K], p3: MP3[K]): MR[K] {
return { p1, p2, p3 } as any;
}
type FooFnChain = FnChain<typeof foo>;
type FooFnChainExpected =
| { params: ["a1", "a2", "a3"]; result: "ar" }
| { params: ["b1", "b2", "b3"]; result: "br" };
π Motivating Example
// [p1: keyof MP2, p2: "a2" | "b2", p3: "a3" | "b3"]
type FooParameters = Parameters<typeof foo>;
// "ar" | "br"
type FooReturn = ReturnType<typeof foo>;
// @ts-expect-error
foo('a1','b2','b3')
// no error
const a:FooParameters = ['a1', 'b2', 'b3']
void a
// no error
curry(foo)('a1')('b2')('b3')
// "ar" | "br"
const r = curry(foo)('a1')('a2')('a3')
π» Use Cases
// @ts-expect-error
foo('a1','b2','b3')
// @ts-expect-error
const a:FnChain<typeof foo>['params'] = ['a1', 'b2', 'b3']
void a
// @ts-expect-error
curry(foo)('a1')('b2')('b3')
// "ar"
const r = curry(foo)('a1')('a2')('a3')
Suggestion
π Search Terms
strict Parameters<T>associated ReturnType<T>curry functionβ Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Given
π Motivating Example
π» Use Cases