-
Notifications
You must be signed in to change notification settings - Fork 237
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
Generating js output of the ts file #244
Comments
I am not sure what you exactly mean. When I use following settings in test: settings.outputFileType = TypeScriptFileType.implementationFile;
settings.outputKind = TypeScriptOutputKind.module;
settings.mapEnum = EnumMapping.asEnum;
settings.nonConstEnums = true; generated enum looks like this: export enum Direction {
North = "North",
East = "East",
South = "South",
West = "West",
} When you are generating implementation file ( When I compiled this TypeScript code I got following JavaScript code: var Direction;
(function (Direction) {
Direction["North"] = "North";
Direction["East"] = "East";
Direction["South"] = "South";
Direction["West"] = "West";
})(Direction = exports.Direction || (exports.Direction = {})); So when you import this file then Is this what you expect? |
You are absolutely right.
The point is, I generate ts code and push it to a separate repository, say
`generated-types` automatically in each build. This generated repository is
added to frontend repo as an npm dependency. So it will be used from within
node_modules in frontend code, and therefore typescript assumes this is
already transpiled to js, and looks for a js file beside it, which doesn't
exist, and therefore nothing is emitted in the final bundle for enums, and
they end up being undefined.
If typescript-generator would support generating transpiled js in addition
to ts file, everything would work great.
…On Thu, Jul 12, 2018, 5:27 PM Vojtěch Habarta ***@***.***> wrote:
I am not sure what you exactly mean. When I use following settings in test:
settings.outputFileType = TypeScriptFileType.implementationFile;
settings.outputKind = TypeScriptOutputKind.module;
settings.mapEnum = EnumMapping.asEnum;
settings.nonConstEnums = true;
generated enum looks like this:
export enum Direction {
North = "North",
East = "East",
South = "South",
West = "West",
}
When you are generating implementation file (*.ts) you need to compile it
somewhere to *.js file.
When I compiled this TypeScript code I got following JavaScript code:
var Direction;
(function (Direction) {
Direction["North"] = "North";
Direction["East"] = "East";
Direction["South"] = "South";
Direction["West"] = "West";
})(Direction = exports.Direction || (exports.Direction = {}));
So when you import this file then Direction should be usable.
Is this what you expect?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#244 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADATZgRN3D-2hbmtWE9yBoKVhRKnBXzcks5uF0e2gaJpZM4VMvXh>
.
|
This is really disadvantage of generating I don't have any plans to generate JavaScript code because that's really responsibility of TypeScript compiler. It is possible to generate |
I see. Though I'm intentionally generating |
Closing the issue (as part of cleanup after release). |
We are using this plugin to maintain a generated npm package for types and use that in frontend via npm.
The problem is that Enums don't work at runtime, and are undefined. We use
<mapEnum>asEnum</mapEnum>
and<nonConstEnums>true</nonConstEnums>
and also<outputFileType>implementationFile</outputFileType>
.When I put the js transpiled version of the generated types beside it, it works fine but without that, enums are undefined in runtime.
The text was updated successfully, but these errors were encountered: