现在我使用这个类型别名:
export type Country = {
name: 'USA' | 'Russia' | 'Bulgaria' | 'Romania' | 'Austria' | 'Great Britain' | 'Italy',
code: 'us' | 'ru' | 'bg' | 'ro' | 'au' | 'gb' | 'it'
};
Run Code Online (Sandbox Code Playgroud)
但它允许创建不正确的对象:
{ name: 'USA', code: 'ru'}
Run Code Online (Sandbox Code Playgroud)
为此目的制作类型的最佳方法是什么?