I have an object in a project that I'm trying to type:
export const dateFormat = {
hourOnly: { hour: 'numeric' }
…
}
I know that the values in this object should fit Intl.DateTimeFormatOptions so I tried:
export const dateFormat: {[key: string]: Intl.DateTimeFormatOptions} = {
hourOnly: { hour: 'numeric' }
…
}
This works but I lose the ability to get auto complete for this object elsewhere in the project. I tried adding as const at the end, but that didn't help.
Is there a way to enforce an objects values while still getting auto-complete for the keys?
I also tried:
type dateFormatOptions = 'hourOnly'
export const dateFormat: {[key: dateFormatOptions]: Intl.DateTimeFormatOptions} = {
hourOnly: { hour: 'numeric' }
…
}
but in this case typescript says the index signature should be a string or a number?