我正在为第 3 方 js 库创建一个 TypeScript 定义文件。其中一种方法允许使用选项对象,选项对象的属性之一接受列表中的字符串:"collapse"、"expand"、"end- expand"和"none"。
"collapse"
"expand"
"end- expand"
"none"
我有一个选项对象的接口:
interface IOptions { indent_size?: number; indent_char?: string; brace_style?: // "collapse" | "expand" | "end-expand" | "none" }
接口是否可以强制执行此操作,因此如果您IOptions在属性中包含一个对象brace_style,它将只允许接受列表中的字符串吗?
IOptions
brace_style
这在 1.8 版中作为“字符串文字类型”发布
Typescript 中的新功能 - 字符串文字类型
页面示例:
interface AnimationOptions { deltaX: number; deltaY: number; easing: "ease-in" | "ease-out" | "ease-in-out"; }