[英]Typescript generic type for all variables defined
I have an object like below: 我有一个类似下面的对象:
var objContainer = {};
objContainer.string1 = "some string";
objContainer.string2 = "some string";
....
objContainer.stringN = "some string";
I want to create a type for objContainer variable in TypeScript.The point is, the variable count and names are unknown. 我想在TypeScript中为objContainer变量创建一个类型。要点是,变量计数和名称未知。 So, I want to introduce a logic like "for each variable inside objContainer's type class will be string type, disregarding its name".
因此,我想引入一种逻辑,例如“对于objContainer的类型类中的每个变量都是字符串类型,而不考虑其名称”。 Is there any way to accomplish that?
有什么办法可以做到这一点? Pseudo-code example is:
伪代码示例为:
interface ExampleInterface{
objContainer:ExampleClass;
}
class ExampleClass{
{All Variables}:string;
}
Probably you want to use interface like this: 可能您想使用这样的界面:
interface Map
{
[K: string]: string;
}
let dict: Map = {};
dict["string1"] = "some string";
let val = dict["string1"];
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.