In the following code snippet, my goal is to have the argument type of fn
inferred based on the values provided in args
.
I aim for good
to be automatically inferred as boolean, num
as a number and bad
to trigger an error.
Currently, all of them are considered as having the type string | number | boolean
, without any errors being raised.
type CustomizeArgs<
Args extends {
[key: string]: { value: [string, string | number | boolean] };
} = {
[key: string]: { value: [string, string | number | boolean] };
},
Arg extends keyof Args = keyof Args
> = {
args: Args;
fn: (params: { [key in Arg]: Args[Arg]["value"][1] }) => void;
};
const configurations: WithArgs[] = [{
args: { good: { value: ["bool", true] } },
fn: ({ good, bad }) => {}
}, {
args: { num: { value: ["number", 5] } },
fn: ({ num }) => {}
}];