I am using the following code.
type PersonRow = {
name: string;
email: string;
phone_number: string;
age: number;
}
const personColumnNames: (keyof Omit<PersonRow, 'age'>)[] = [
'name',
'email',
'phone_number'
];
However I want to get an error when I remove phone_number
from the personColumnNames (in case a column is ever added to the PersonRow type).
type PersonRow = {
name: string;
email: string;
phone_number: string;
age: number;
}
const personColumnNames: (keyof Omit<PersonRow, 'age'>)[] = [
'name',
'email'
];
Edit:
Here is a hacky way I found but this still seems less than ideal.
const personColumnNames = Object.keys(((): { [key in keyof Omit<PersonRow, 'age'>]: null } => ({
name: null,
email: null,
phone_number: null,
}))())