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

Ability to choose between a declared module or an exported module when generating types #20

Open
SafeerH opened this issue Jun 2, 2019 · 2 comments

Comments

@SafeerH
Copy link
Collaborator

SafeerH commented Jun 2, 2019

Problem

I used to access my enum values (in a type-safe way) from my Angular view whenever I needed, by exposing it from my component as below.

E.g.

// my-enum.ts
export enum MyEnum {
  Ebay = 'Ebay',
  Amazon = 'Amazon',
}

// my-component.ts
import { MyEnum } from 'my-enum';

export class MyComponent {
  MyEnum: typeof MyEnum = MyEnum;
}

Now I'm running into to a problem where I can't access my generated enum values from my Angular view as I used to do because of the generated enums are defined under a declared module.

// my-component.ts
export class MyComponent {
  MyEnum: typeof ApiModel.MyEnum = ApiModel.MyEnum;
}
// ERROR: **ReferenceError: ApiModel is not defined**

Solution

The solution for this problem would be to generate types (e.g. enums) under an exported module (instead of a declared module as the declare keyword will not generate any JS code and only being used by the TS compiler)

So, it would be nice to have an option in the config file to choose between a declared module (e.g. model.d.ts) or an exported module (e.g. model.ts) when generating types.

@svenheden
Copy link
Owner

That's a great suggestion, feel free to do a PR! 🙏🏼

@wzuqui
Copy link

wzuqui commented Oct 20, 2019

I had a problem like yours, my frontend project is angular and needed to export enum and classes, try my project, we can help each other.

#38

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

Successfully merging a pull request may close this issue.

3 participants