I have an type with props that can be optional depending on a generic type:
type MyType<R extends Record<string, string> | undefined, A extends string[] | undefined> = {
record: R
array: A
}
I have a function that takes a MyType
object
const myFunction = <R extends Record<string, string> | undefined, A extends string[] | undefined>(myObject: MyType<R, A>)=>{
// ... //
}
I want to be able to call myFunction
and omit a record
in the props if R
is undefined, for example
const record = getTheRecord() // Assuming getTheRecord() returns a undefined here
const array = ['a']
myFunction<undefined, string[]>({
array
})
How can I make some props optional depending on a generic type?