Is it possible to generate a new type from an array in Typescript?
I have a list of months in a variable, is there a way to generate a new type as MonthName: MonthNumber
For example:
const Months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
] as const;
The output should be:
type MonthsWithNumber = {
'January': 01,
'February': 02,
'March': 03,
'April': 04,
'May': 05,
'June': 06,
'July': 07,
'August': 08,
'September': 09,
'October': 10,
'November': 11,
'December': 12
}