Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to emit file with named constants #25

Closed
zspitz opened this issue Jan 30, 2017 · 2 comments
Closed

Option to emit file with named constants #25

zspitz opened this issue Jan 30, 2017 · 2 comments

Comments

@zspitz
Copy link
Owner

zspitz commented Jan 30, 2017

Currently,

  • Javascript doesn't have any mechanism to access static members, only creatable objects (new ActiveXObject(...))
    • modules -- collection of named constants
    • enums -- two aspects:
      1. named constants
      2. limited set of values
  • Typescript's const enum can be used to model ActiveX enums, because they can be defined in an ambient context and the values are inlined into the calling code
    • but only for ActiveX enums; ActiveX modules do not constrain to a limited set of values, only assign names to them
  • const enum is limited to numbers. This means:
    • no string-based enums, or enums of any other type

Non-numeric enums should be emitted as type declarations, which will allow for compile-time limitation to those values.

type CommandID = 
    "{04E725B0-ACAE-11D2-A093-00C04F72DC3C}" |
    "{E208C170-ACAD-11D2-A093-00C04F72DC3C}" ...

COM modules should be emitted as an additional file with runtime-assigned constants.

namespace CommandID { 
  const wiaCommandChangeDocument = "{04E725B0-ACAE-11D2-A093-00C04F72DC3C}";
  const wiaCommandDeleteAllItems = "{E208C170-ACAD-11D2-A093-00C04F72DC3C}";
  const wiaCommandSynchronize = "{9B26B7B2-ACAD-11D2-A093-00C04F72DC3C}";
  const wiaCommandTakePicture = "{AF933CAC-ACAD-11D2-A093-00C04F72DC3C}";
  const wiaCommandUnloadDocument = "{1F3B3D8E-ACAE-11D2-A093-00C04F72DC3C}";
}

See also here

@zspitz zspitz added the writer label Jan 31, 2017
@zspitz zspitz changed the title Generate constants file Option to emit file with named constants Jan 31, 2017
zspitz added a commit that referenced this issue Jan 31, 2017
@zspitz zspitz added the ui label Feb 15, 2017
zspitz added a commit that referenced this issue Feb 23, 2017
@zspitz
Copy link
Owner Author

zspitz commented May 17, 2017

With the introduction of microsoft/TypeScript#15486, it is now possible to output const enums with string values in definition files, as well as mixed string/numeric enums.

@zspitz zspitz closed this as completed May 17, 2017
@zspitz zspitz reopened this Jun 21, 2017
@zspitz zspitz closed this as completed Jun 21, 2017
@zspitz
Copy link
Owner Author

zspitz commented Jun 22, 2017

Fixed with f97a380. Modules and all enums (numeric/non-numeric) are outputted as const enum.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant