Let's say I have a function that outputs the following:
interface result {
A?: string;
B?: string;
C?: string;
}
When using an array parameter in a function, how can I make certain return parameters non-nullable and required? For example:
function toRequired(keysToTurnRequired: string[]): CorrectResult {
}
If I were to execute toRequired(['A', 'B'])
, then my return type should be updated to this:
result {
A!: string;
B!: string;
C?: string;
}
Is there a generic method in Typescript to achieve this easily? This would greatly enhance type safety when working with ORM repositories.