In the following example, is it possible for the type of P
to be inferred from the entries in the props
array, rather than having to define it twice?
type A = {
one: boolean
two: number
three: string[]
four: string
}
type Definition<T, P extends (keyof T)[]> = {
props: P
}
const def: Definition<A, ['one', 'three', 'four']> = {
props: ['one', 'three', 'four']
}
playground
Note – the above example is massively simplified for the purpose of this question. The type of P
is also needed to calculate additional parts of a mapped type