Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 表示元组类型的类型,对象的键为字符串文本_Typescript - Fatal编程技术网

Typescript 表示元组类型的类型,对象的键为字符串文本

Typescript 表示元组类型的类型,对象的键为字符串文本,typescript,Typescript,给定一个接口: interface EPostageInsertExEvent_Parameter { readonly Doc: Word.Document; cpDeliveryAddrStart: number; cpDeliveryAddrEnd: number; readonly cpReturnAddrStart: number, readonly cpReturnAddrEnd: number; readonly xaWidth: n

给定一个接口:

interface EPostageInsertExEvent_Parameter {
    readonly Doc: Word.Document;
    cpDeliveryAddrStart: number;
    cpDeliveryAddrEnd: number;
    readonly cpReturnAddrStart: number,
    readonly cpReturnAddrEnd: number;
    readonly xaWidth: number;
    readonly yaHeight: number;
    readonly bstrPrinterName: string;
    readonly bstrPaperFeed: string;
    readonly fPrint: boolean;
    fCancel: boolean;
}
如何将由该接口的键组成的元组类型定义为字符串文本?换句话说,等同于以下内容:

type EPostageInsertExEvent_ArgNames = ['Doc', 'cpDeliveryAddrStart', 'cpDeliveryAddrEnd',
    'cpReturnAddrStart', 'cpReturnAddrEnd', 'xaWidth', 'yaHeight', 'bstrPrinterName',
    'bstrPaperFeed', 'fPrint', 'fCancel'];

这在TypeScript中目前不可能实现。GitHub中有一个允许这样做的插件,但是在那里没有太多的移动。你可能想要去给它一个数组,你想要一个元组还是一个字符串数组?您想在设计或运行时使用它?@RodrigoPedrosa该类型应该是元组类型,由字符串文本组成。“我想在设计时就写出来。我想你已经在你的问题中写出来了。”罗德里戈佩德罗萨,这个想法不是你自己写出来的。见下面我的答案。