【发布时间】:2022-01-14 10:31:09
【问题描述】:
我想做的就是这么简单。
在下面的例子中,
interface InterfaceA { a: string, b: number }
interface InterfaceB { c: keyof InterfaceA }
const testMethod = (test: InterfaceB) => {
const TestObject: InterfaceA = { a: '', b: 1 }
TestObject[test.c] =
}
导致 'Type 'any' is not assignable to type 'never'' 错误。
我认为 test.c 可以在 TestObject 中赋值,因为 c 是接口 A 的键。
我怎样才能让事情顺利进行?
【问题讨论】:
-
能否请您编辑您的问题以包含一个完整且可验证的示例。您目前提供的内容不足以让我们为您提供帮助。使用typescript playground,您可以在问题中包含指向工作示例的链接。
-
@Olian04 感谢您的建议!我用一个更简单的问题编辑了我的问题。
标签: string typescript types typescript-never