Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.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
Javascript 如何使用实现接口制作Typescript枚举_Javascript_Node.js_Typescript_Types_Enums - Fatal编程技术网

Javascript 如何使用实现接口制作Typescript枚举

Javascript 如何使用实现接口制作Typescript枚举,javascript,node.js,typescript,types,enums,Javascript,Node.js,Typescript,Types,Enums,如何使用实现接口制作Typescript枚举 我当前有2个枚举 所有enum ENNAME键应仅包括ofenum POSTAG键 export enum POSTAG { BAD = 0x80000000, D_A = 0x40000000, D_B = 0x20000000, D_C = 0x10000000, } export enum ENNAME { D_A = 'a', D_B = 'b', D_C = 'c', } 有没有

如何使用实现接口制作Typescript枚举

我当前有2个枚举

所有
enum ENNAME
键应仅包括of
enum POSTAG

export enum POSTAG
{
    BAD = 0x80000000,
    D_A = 0x40000000,
    D_B = 0x20000000,
    D_C = 0x10000000,
}

export enum ENNAME
{
    D_A = 'a',
    D_B = 'b',
    D_C = 'c',
}

有没有办法做这样的东西

export interface ENNAME
{
    [k: keyof POSTAG]: string,
}

无法创建
枚举
扩展
接口
。最好是设置一些类型的编译时检查,以便在出错时生成警告,例如:

interface ENNAMEInterface extends Record<Exclude<keyof typeof POSTAG, "BAD">, string> { }
type VerifyExtends<T, U extends T> = true
type VerifyENNAME = VerifyExtends<ENNAMEInterface, typeof ENNAME>; // okay
希望有帮助。祝你好运

export enum ENNAME {
  D_A = 'a',
  D_B = 'b',
  // oops, D_C is missing 
}

type VerifyENNAME = VerifyExtends<ENNAMEInterface, typeof ENNAME>; // error
//                                                 ~~~~~~~~~~~~~
//  Property 'D_C' is missing in type 'typeof ENNAME' but required in type 'ENNAMEInterface'.