question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] typescript-fetch should not use namespaces (SyntaxError: Namespaces are not supported.)

See original GitHub issue

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What’s the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What’s the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Generated files result in error: (e.g. in create-react-app with TypeScript support)

./src/api/profile/models/Culture.ts
SyntaxError: C:\Users\ceefour\git\heartenly-pwa\src\api\profile\models\Culture.ts: Namespaces are not supported.
  110 |  * @namespace Culture
  111 |  */
> 112 | export namespace Culture {
      |        ^
  113 |     /**
  114 |      * @export
  115 |      * @enum {string}

Adding configuration supportsES6: true doesn’t help.

Via @DanielRosenwasser - https://github.com/facebook/create-react-app/pull/4837#issuecomment-430107471 :

TypeScript PM here. Broadly speaking, I feel that

namespaces are not a huge loss; the React community is firmly on-board with ES modules anyway, and that’s the direction the TypeScript world is taking. const enums are often misused. Sure, they can be great for the internals of a library to get some speed improvements, but they generally shouldn’t be used outside of that scope. Merging behavior is marginally useful now that TypeScript 3.1 has the ability to tack properties onto functions. The fact that enums merge is also something I’ve never seen used out in the wild.

via @Timer - https://github.com/facebook/create-react-app/issues/5681#issuecomment-435372634 :

I’m sorry and understand that this is likely frustrating, but namespaces are a proprietary, legacy feature. They have been replaced by specification behavior: ES Modules. Namespaces are deprecated. The TypeScript documentation is going to remove all references to them in examples and stop usage. In other words, you should not be using namespaces anymore. Const Enums are rarely needed and often misused.

openapi-generator version

0.0.7-4.0.0-beta

OpenAPI declaration file content or url

anything that uses enum

Command line used for generation
openapi-generator generate -i E:\tmp\lovia-heartenly-profile-4.0-swagger.yaml -g typescript-fetch -o src/api/profile
Steps to reproduce
  1. generate using typescript-fetch
  2. @babel/preset-typescript won’t compile, and the generated files use deprecated namespace feature
Related issues/PRs
Suggest a fix

Remove the namespace and use the enum directly in the module.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
denyocommented, Jan 22, 2019

@ceefour your suggestion

Remove the namespace and use the enum directly in the module.

works as long as their isn’t another enum with the same name.

For instance with the pet store examples that’s the case and you end up with the following error within the models barrel:

[ts] Module './Order' has already exported a member named 'StatusEnum'. Consider explicitly re-exporting to resolve the ambiguity. [2308]

So to prevent this I’d suggest to prefix the enum with the namespace.

0reactions
macjohnnycommented, Mar 22, 2019

@Rassilion you could add this to your plans and support us fixing it 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

No namespace support after upgrading Babel in React Native?
My knowledge to React Native is limited, but I do know quite a long about transpilers/bundlers. Your upgrade clearly includes babel's new ...
Read more >
Documentation - Namespaces - TypeScript
How TypeScript namespaces work. ... “Internal modules” are now “namespaces”. ... are left unexported and will not be visible to code outside the...
Read more >
babel/plugin-proposal-export-namespace-from
NOTE**: This plugin is included in `@babel/preset-env`, in [ES2020](https://github.com/tc39/proposals/blob/master/finished-proposals.md)
Read more >
How To Use Namespaces in TypeScript - DigitalOcean
This tutorial will reference aspects of text editors that support TypeScript and show in-line errors. This is not necessary to use TypeScript ...
Read more >
Is typescript Namespace feature deprecated? - Michele Nasti
The guy who wrote the library was not expert in typescript (but he ... so he rewrote entire parts of the app using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found