-
-
Notifications
You must be signed in to change notification settings - Fork 40
Cannot use const enums from plugins #1012
Comments
Hi @PeterStaev, We've missed documenting this case. When exposing a const enum from a plugin, you have to define it in a In other words, in the attached example, you need the following files: export const enum IntEnum {
X,
Y,
Z
}
export const enum StringEnum {
X = "x",
Y = "y",
Z = "z",
}
export function test() {
return "this is a test";
}
|
@DimitarTachev , how will this work in an actual plugin published on NPM? For example here: https://github.com/PeterStaev/nativescript-telerik-reporting/tree/master/reporting/document I have a TS file that during compile of the plugin is transpiled to JS and this is what is included in the plugin package. Then I have a Also as far as I understand that compile option should be set for the app and not the plugin, right? |
When you set the P.S. You could also keep the enum declarations in the |
@DimitarTachev , I've just tried your solution, but this is far from ideal. Adding this compile option, makes the const enum work just like a normal enum, i.e. it gets a "class" created within the JS file of the plugin. Not only that, but then in the code using the plugin the members are not replaced with the constant value, but instead are using the generated class... So you might as well say in the docs that |
Developing a plugin, you have to ensure that your const enums could be used both from the I suppose that if you do not emit the enum classes in the JS files, your plugin cannot be used in NativeScript Core JS flavor even with NativeScript 5.4. Did your setup work properly in this flavor before NativeScript 6.0? The only difference in NativeScript 6.0 should be in the NativeScript Core TS flavor. As recommended by the As far as I know, the const enums are still inlined by default in Angular apps and the users are able to enable them in NativeScript Core TS apps by disabling the If you want to optimize the enum calls in your plugin and inline them, you could execute multiple TypeScript compilations and have both inlined enums and generated enum classes in the JS files but I don't believe it worth it. |
@DimitarTachev , the plugin was working fine prior to 6.0 in both webpacked and non-webpacked apps. For people using Core JS flavor, they would have to type the string themselves, instead of using the enum. But for people using TS they would be able to use the intellisense of the const enum in the I could use a specific type for this (i.e. |
Thanks for the additional details. I'm closing this issue because as I've already said, this limitation is caused by the Also, even before the |
Environment
Provide version numbers for the following components (information can be retrieved by running
tns info
in your project folder or by inspecting thepackage.json
of the project):CLI: 6.0.0
Cross-platform modules: 6.0.0
Android Runtime:6.0.0
iOS Runtime:6.0.0
Plugin(s):
Node.js: 10.16.0
Please, attach your package.json and webpack.config.js as these configurations are usually critical for investigating issues with webpack
Describe the bug
Previously it was possible to have an exported
const enum
defined in a plugin's.d.ts
and then use its values in the app. With the new web pack only workflow and new version of the web pack plugin this is no longer possible.To Reproduce
Expected behavior
Users should be able to use const enums defined in the
.d.ts
files of plugins/npm packages.Sample project
const-enum-imports.zip
Tried both with
export const
anddeclare const
in the.d.ts
but neither are working.Additional context
The text was updated successfully, but these errors were encountered: