【发布时间】:2021-07-05 17:37:57
【问题描述】:
如果有更合适的标题,请告诉我。
例如,我在 AB 类型中添加 C。我希望在 ABSentences 中出现类型检查错误。
示例代码
type AB = {
A?: any
B?: any
}
const ABSentences: { [key in keyof Required<AB>]: string } = {
A: 'this is A.',
B: 'this is B.',
} as const
我想使用type AB 来保护ABSentences 的密钥。
你有什么好主意吗?
ABSentences的实际类型
const ABSentences: {
A: string;
B: string;
}
期望类型的 ABSentences
const ABSentences: {
A: 'this is A.';
B: 'this is B.';
}
【问题讨论】:
标签: typescript