Skip to content

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

Closed
@ceefour

Description

@ceefour

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 - facebook/create-react-app#4837 (comment) :

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 - facebook/create-react-app#5681 (comment) :

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions