A TypeScript beginner here.
I have the following type definition for a function:
type MappingCallback<A extends any[], B extends any[]> = (from: A[0], to: B[0]) => boolean
interface ArrayToCombine<A extends any[], B extends any[]> {
array: B
mapping: MappingCallback<A, B>
propertyName: string
}
declare function augmentArray<A extends any[], B extends any[], C extends any[]>(
base: A,
arrays: [ArrayToCombine<A, B>, ArrayToCombine<A, C>]
) : A
export default augmentArray
Right now, if I add another element to the arrays
parameter, I also have to add a new ArrayToCombine<A, ?>
element to the type definition to work. Is there a way to make it dynamic, so each element in the arrays list will inherit the correct type, (the type is coming from the array
property inside ArrayToCombine
interface)
(Also, you can see I have to define extends any[] on each generic type, otherwise, VSCode underlines it as an error)
Please tell me if I should clarify something, or you need more info!