In my app, I have a specific type with optional props based on a generic type:
type MyCustomType<R extends Record<string, string> | undefined, A extends string[] | undefined> = {
record: R,
array: A
}
There is a function that directly uses the MyCustomType
:
const customFunction = <R extends Record<string, string> | undefined, A extends string[] | undefined>(myData: MyCustomType<R, A>)=>{
// ... //
}
The requirement is to be able to omit the record
prop if it's not defined in the generic type. Here's an example:
const recordInfo = getTheRecord() // Assuming getTheRecord() returns undefined here
const sampleArray = ['a']
customFunction<undefined, string[]>({
array: sampleArray
})
Is there a way to make certain props optional in relation to a generic type?