Git Product home page Git Product logo

Comments (5)

WhiteMinds avatar WhiteMinds commented on May 18, 2024 1

呃,#12 不用重新打开,那个是我试了下 github 的在线编辑功能,还挺好使的。

因为 GuardLevel 导出时用的是 export type,所以不会编译到 js 里,GuardLevel 这个变量实际上不存在于 dist/index.js 中。
类型上是没问题,但是当作数据来用的话会出问题,比如 identity.guard_level === GuardLevel.Zongdu

from blive-message-listener.

WhiteMinds avatar WhiteMinds commented on May 18, 2024

另外,定义了 enum 但只导出它的 type 这个行为其实也不太好,包的使用者还得自己再定义遍 enum

from blive-message-listener.

ddiu8081 avatar ddiu8081 commented on May 18, 2024

感谢指出!我看 #12 被 Close 了没有合并,需要重新打开么?

另外,定义了 enum 但只导出它的 type 这个行为其实也不太好,包的使用者还得自己再定义遍 enum

在我个人使用来看,是通过 import type { GuardLevel } from 'blive-message-listener' 就可以导入并使用的,似乎不用重新定义?

from blive-message-listener.

ddiu8081 avatar ddiu8081 commented on May 18, 2024

v0.3.1 已修正;
枚举在 JavaScript 环境使用的话似乎没想到什么方案(枚举改为导出 Object?)目前我的想法还是 TS 用枚举 JS 用 number 判断🤔

from blive-message-listener.

WhiteMinds avatar WhiteMinds commented on May 18, 2024

v0.3.1 已修正; 枚举在 JavaScript 环境使用的话似乎没想到什么方案(枚举改为导出 Object?)目前我的想法还是 TS 用枚举 JS 用 number 判断🤔

就正常编译到 es5 成 object 就行,tsc 把 enum 编译成 object 后,类型上还是 enum。
目前这种情况 TS 开发环境下也用不了枚举,因为 import 出来的只有类型,必须手动重新定义一个同样的 enum。
或者可以转一遍数据变成字符串的版本:

export type GuardLevel = 'None' | 'ZongDu' | 'TiDu' | 'JianZhang'

from blive-message-listener.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.