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

Refactor Typescript generation to not use Namespaces #1189

Closed
wgottschalk opened this issue Mar 22, 2019 · 2 comments
Closed

Refactor Typescript generation to not use Namespaces #1189

wgottschalk opened this issue Mar 22, 2019 · 2 comments

Comments

@wgottschalk
Copy link
Contributor

Babel 7 parses typescript and can confirm that they refuse to implement namespaces due to the fact that they are legacy. babel/babel#8244

When parsing from JSON schema to typescript the Convert function is wrapped in a namespace.

Solution:

Refactor the Convert function to be a const instead of a namespace. Do not export any of the helpers still.

before:

export namespace Convert {
  export function toThing(data: string): Thing {...}
  export function thingToJSON(data: Thing): string {...}
}

after:

export const Convert = {
  toThing() {...}
  thingToJSON() {...}
}

// rest of the helpers go here and are not exported
@schani
Copy link
Member

schani commented Mar 22, 2019

Would you consider contributing a PR that does this? We'd love to help you along. The code that emits TypeScript is here and here.

@wgottschalk
Copy link
Contributor Author

Sounds good to me. I'll talk a look at this

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

No branches or pull requests

2 participants