To start, it is recommended to utilize the typeof operator as mentioned in a previous response.
Additionally, if I interpret your query correctly, you aim to construct a type that specifically encompasses these exact three provided values. In order to achieve this, you should employ the as const
keywords.
Here is an illustration:
export const X = 1 as const;
export const Y = 2 as const;
export type CustomType = typeof X | typeof Y;
Furthermore, consider this practical example utilizing const variables:
export const state = {
ACTIVE: 1,
INACTIVE: 2
} as const;
export type StateType = typeof state[keyof typeof state];
export interface IEntity {
id: number;
status: StateType;
}
// This can be applied elsewhere in this manner:
const Z: IEntity = {
id: 1,
status: state.ACTIVE
};