【发布时间】:2022-11-10 18:53:30
【问题描述】:
我有我想用作类型的对象:
interface MyInput {
id: string,
label: string,
setter: Function,
type: string,
value: string | string[] | boolean,
options?: string[]
}
我有一些错误,例如:类型“字符串”上不存在属性“地图”|布尔值 |细绳[]'。 键入'字符串 |布尔值 | string[]' 不可分配给类型 'boolean |不明确的'。
问题是我将始终知道我的值是字符串 []、布尔值还是带有类型属性的字符串。
是否有任何解决方案可以在不创建 3 个不同界面的情况下消除这些错误?
除了将我的价值属性用于任何或创建 3 种不同类型之外,我不知道。
【问题讨论】:
-
The thing is that I will always know whether my value is string[], boolean or string with my type property.你能说的更具体点吗?你(人类)在寻找什么来判断它会是什么?
标签: javascript typescript next