![](/img/trans.png)
[英]How should I declare a variable that will have the value of setInterval?
[英]What value type should i declare an object variable
我有一个简单的对象,类型为{[key]:[[array]], [key]:[[array]]}
:
const types = {
first: 'type1',
second: 'type2',
}
const myobj = {
'[types.first]': [
['blue', 'small', true, 200, 300, undefined, 150],
['blue', 'large', true, 560, 600, 300, 150],
],
'[types.second]': [
['red', 'xlarge', true, 400, 400, 200, 1],
['red', 'xxlarge', true, 500, 500, undefined, 2]
]
}
我需要帮助来声明对象的类型,例如: const myobj: 'type of the object' = {....}
像{[key: string]: [[]]}
,但我无法使其正常工作。
您的对象值实际上是元组类型的数组,可以将其键入为:
{ [key: string]: Array<[string, string, boolean, number | undefined, number | undefined, number | undefined, number | undefined]> }
我已经创建了对象的接口,然后将该接口作为参考传递,所以说我有这个对象
"market_actions": [{
"link":"steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D2796249422649106588",
"name": "Inspect in Game..."
}]
这就是以下对象的类型
export interface IDescription {
market_actions: IDAction[]
}
export interface IDAction {
link: string
name: string
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.