类内的枚举(TypeScript定义文件) [英] Enum inside class (TypeScript definition file)

查看:212
本文介绍了类内的枚举(TypeScript定义文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了一下,但似乎找不到答案,希望可以为您提供帮助.如何在图像中添加枚举?这是我理想的状态,但出现错误.

I've searched around but can't seem to find an answer for this, hopefully you can help. How can I add an enum to Image? This is what I would like ideally but I get an error.

declare module 'Lib' {

  export module Graphics {

    export class Image {

      enum State {}

      static STATE_IDLE: State;
      static STATE_LOADING: State;
      static STATE_READY: State;
      static STATE_ERROR: State;

      constructor();

    }

  }

}

如果我将State移入Graphics模块,那么它可以工作,但现在State属于Graphics ...这是不正确的,它必须是Image的一部分.

If I move State into the Graphics module it works but now State belong to Graphics...which is incorrect, it needs to be part of Image.

有什么想法吗? 谢谢

推荐答案

我想我可能已经找到了解决方案……我不知道它是否是有效的TypeScript,但它可以工作并且不会引起任何编译错误.这是上述答案的组合.

I think I may have found a solution...whether it's valid TypeScript I don't know but it works and doesn't cause any compile errors. It's a combination of the above answers.

declare module 'Lib' {

  module Graphics {

    module Image {
      enum State { }
      var STATE_IDLE: State;
      var STATE_LOADING: State;
      var STATE_READY: State;
      var STATE_ERROR: State;
    }

    class Image {
      constructor();
    }

  }

}

有人能发现我没有注意到的任何潜在问题吗?

Can anyone spot any potential issues with this that I haven't noticed?

这篇关于类内的枚举(TypeScript定义文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆