下面的类型声明有误
type Storable = undefined | boolean | number | string | Storable[] | {
[key in string]: Storable;
}
报错:
Index signature is missing in type "XXX"
有好方法能实现这种类型吗?
// 需要满足
let a: Storable
a = 5
a = "string"
a = [5, "string"]
a = {
key: {
whatever: [
5,
"string",
{
key: 23
}
]
}
}
// 但不能是 Function 或 Map 或其他千奇百怪的类型
// wrong
a = function () {
// pass
}
// wrong
a = new Map()
// wrong
a = {
key: new Map()
}