2021-06-09

In [[TypeScript]] there are two syntaxes (are there more?) for defining a type of an object, either [[Index signature]] or the [[Record utility]]. In my opinion, the Record syntax looks more readable.
type Server = 'dev' | 'stage' | 'production'

// Index signature
const serversIndex: { [key in Server]: string } = {
dev: 'url-dev',
stage: 'url-stage',
production: 'url-production'
} as const

// Using the Record utility
const serversRecord: Record<Server, string> = {
dev: 'url-dev',
stage: 'url-stage',
production: 'url-production'
} as const