Let's consider a scenario where we have the following interface:
interface OrderPurchase {
headerName: string;
minWidth: number;
}
We also have an array of objects as shown below:
const columns: OrderPurchase[] = [
{
headerName: 'ID',
minWidth: 78,
},
{
headerName: 'Email',
minWidth: 250,
},
{
headerName: 'Name',
minWidth: 180,
},
{
headerName: 'Country',
minWidth: 80,
},
{
headerName: 'Total',
minWidth: 80,
}];
The question arises on how to define a type HeaderName that is restricted to specific values used in the key within the array. In this particular case, HeaderName should only be allowed to take on values such as ID, Email, Name, Country, or Total.
An attempted solution was made using the code snippet below, but it seems to only limit values to string:
type HeaderName = typeof columns[number]['headerName'];