typescript 打字稿创建匿名对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45206336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Typescript create anonymous objects
提问by tmp dev
I want to create a hierarchy of nested objects in typescript that looks like the following
我想在打字稿中创建嵌套对象的层次结构,如下所示
snapshot{
profile{
data{
firstName = 'a'
lastName = 'aa'
}
}
}
I dont want to create a class structure, just want to create the nested hierarchy of objects thats all.
我不想创建一个类结构,只想创建对象的嵌套层次结构。
回答by Jon G St?dle
TypeScript is just JavaScript with some extra sugar on top, so regular anonymous JavaScript objects are legal:
TypeScript 只是在上面添加了一些额外糖分的 JavaScript,因此常规的匿名 JavaScript 对象是合法的:
var snapshot:any = {
profile: {
data: {
firstName: 'a',
lastName: 'aa'
}
}
}