If I have a TypeScript type alias defined like this:
export type PlatformType = 'em' | 'ea' | 'hi';
how can I declare a property in an interface so that that property is an array of exactly one type of each PlatformType
alias? For example, I want this:
export interface Constants {
platformTypes: PlatformType[]; // how to declare a type for platformTypes?
}
so that when I have an object of Constants
type, I need to have this:
export const constants: Constants = {
platformTypes: ['em', 'ea', 'hi']
}
Basically, I would like to get an error if I have this:
export const constants: Constants = {
platformTypes: ['em', 'ea'] // should error, missing 'hi'
}
or
export const constants: Constants = {
// this will error anyway because 'extra' doesn't belong to PlatformType alias
platformTypes: ['em', 'ea', 'hi', 'extra']
}
or
export const constants: Constants = {
platformTypes: ['em', 'em', 'ea', 'hi'] // should error, duplicate 'em'
}