Exploring the code snippet above, an interesting behavior was noticed. It appears that by removing the line validate: (...) => {}
, A
is correctly determined to be rule1: { v: number }
. However, leaving the line intact results in A
being inferred as unknown
. Any insights on what might be causing this discrepancy and any suggestions on how it can be resolved? Thank you in advance :)
type Arguments<A> = {
[K in keyof A]: {
args: {
[K1 in keyof A[K]]: {
assert?: (arg: unknown) => arg is A[K][K1];
}
};
validate?: (value: unknown, args: A[K]) => unknown;
}
}
function test<A>(args: Arguments<A>) {}
test({
rule1: {
args: {
v: {
assert: (arg): arg is number => typeof arg === 'number',
}
},
validate: (value, args) => {
}
}
});