OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript-fetch] TS2339: Property 'map' does not exist on type 'Set '.

Open
#9,383 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hello,

The code generated by openapitools generator does not compile for my app.

openapi-generator version : 5.1.0

export function UserToJSON(value?: User | null): any {
    if (value === undefined) {
        return undefined;
    }
    if (value === null) {
        return null;
    }
    return {
        
        'id': value.id,
        'firstName': value.firstName,
        'lastName': value.lastName,
        'matricule': value.matricule,
        'civility': CivilityToJSON(value.civility),
=>        // This line generates the following error => TS2339: Property 'map' does not exist on type 'Set '.
        'roles': value.roles === undefined ? undefined : (Array.from((value.roles as Set<any>).map(RoleToJSON))),
    };
}
Steps to reproduce

npx @openapitools/openapi-generator-cli generate -i http://localhost:8082/v3/api-docs -g typescript-fetch -o ./src/lib/sdk --additional-properties=typescriptThreePlus --additional-properties=supportES6=true

tsconfig =>

  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": [ "dom","es6",
      "dom.iterable",
      "esnext"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@hlpr-front/utils": ["libs/utils/src/index.ts"],
      "@hlpr-front/hlpr-api-sdk": ["libs/hlpr-api-sdk/src/index.ts"],
      "@hlpr-front/ui": ["libs/ui/src/index.ts"]
    },
    "jsx": "react",
    "forceConsistentCasingInFileNames": true
  },
  "exclude": ["node_modules", "tmp"]
}

OpenAPI model =>

"roles":{"uniqueItems":true,"type":"array","items":{"$ref":"#/components/schemas/Role"}}}}
... "Role":{"type":"object","properties":{"managementJob":...}

Any Help appreciated...

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the typescript-fetch generator output shown in the report, especially UserToJSON and the roles serialization expression. Reproduce the issue with the provided openapi-generator command and TypeScript configuration. Done means the generated TypeScript compiles for the uniqueItems array model without the TS2339 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.