【发布时间】:2021-11-21 03:28:48
【问题描述】:
这是我的字典:
type Words = 'man' | 'sun' | 'person'
type Dictionary = Record<Words,string>
而Dictionary等于这种类型:
type Dictionary = {
man: string;
sun: string;
person: string;
}
目标是让其他程序员知道应该使用 IDE 自动完成将巫婆单词添加到字典中。但它限制了他们添加其他可选词。我试过了,但结果根本不包含单词:
type Words = 'man' | 'sun' | 'person' | string
type Dictionary = Record<Words,string>
// Equals to
type Dictionary = {
[x: string]: string;
}
我怎样才能让单词自动完成,但也可以有可选单词?
【问题讨论】:
标签: typescript type-definition