Say I have declared a type:
type MyCustomType = {
key1: 'value1' | 'value2'
key2: boolean
key3: number
}
I am trying to write some code that will check if all values for a given object of type "MyCustomType" have defined values. e.g.
function validate(input: MyCustomType): boolean {
const fieldsToCheck = ['key1', 'key2', 'key3'] as const;
return fieldsToCheck.every((key) => !!input[key])
}
I can manually define 'fieldsToCheck' like the example, but ideally I would like a way to generate the array from the type definition. Conversely I would be okay with declaring the array, then defining the type relative to that array.
what do?