public static const in TypeScript

前端 未结 8 904
慢半拍i
慢半拍i 2020-12-07 10:11

Is there such a thing as public static constants in TypeScript? I have a class that looks like:

export class Library {
  public static BOOK_SHELF_NONE: stri         


        
8条回答
  •  被撕碎了的回忆
    2020-12-07 10:49

    Here's what's this TS snippet compiled into (via TS Playground):

    define(["require", "exports"], function(require, exports) {
        var Library = (function () {
            function Library() {
            }
            Library.BOOK_SHELF_NONE = "None";
            Library.BOOK_SHELF_FULL = "Full";
            return Library;
        })();
        exports.Library = Library;
    });
    

    As you see, both properties defined as public static are simply attached to the exported function (as its properties); therefore they should be accessible as long as you properly access the function itself.

提交回复
热议问题