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.

Is REST API Codegen broken with TypeScript 4.8?

See original GitHub issue

Hello, I was playing with TypeScript 4.8, and after hitting https://github.com/reduxjs/redux-toolkit/pull/2547 and working around it, it seemed that code generation also failed.

I found that I was still using @rtk-incubator/rtk-query-codegen-openapi, which is no longer mentioned in the docs, instead, the docs recommend using @rtk-query/codegen-openapi, so I switched to it, but the same problem happened:

Please note that `@rtk-query/codegen-openapi` only has been tested with TS versions 4.1 to 4.5 - other versions might cause problems.
Generating ../../../src/generated/api.ts
SyntaxError: Identifier expected. (1:23)
> 1 | import { type api as  } from "../tools/generated-api/base-api";
    |                       ^
  2 | const injectedRtkApi = api.injectEndpoints({
  3 |     endpoints: build => ({
  4 |         get___: build.query<___ApiResponse, Get___ApiArg>({
    at Ve (REDACTED_BASE_PATH/node_modules/prettier/parser-typescript.js:1:15607)
    at vz (REDACTED_BASE_PATH/node_modules/prettier/parser-typescript.js:280:5919)
    at Object.yz [as parse] (REDACTED_BASE_PATH/node_modules/prettier/parser-typescript.js:280:6242)
    at Object.parse (REDACTED_BASE_PATH/node_modules/prettier/index.js:7334:23)
    at coreFormat (REDACTED_BASE_PATH/node_modules/prettier/index.js:8645:18)
    at formatWithCursor2 (REDACTED_BASE_PATH/node_modules/prettier/index.js:8837:18)
    at REDACTED_BASE_PATH/node_modules/prettier/index.js:37229:12
    at Object.format (REDACTED_BASE_PATH/node_modules/prettier/index.js:37243:12)
    at prettify (REDACTED_BASE_PATH/node_modules/@rtk-query/codegen-openapi/src/utils/prettier.ts:35:19)
    at async generateEndpoints (REDACTED_BASE_PATH/node_modules/@rtk-query/codegen-openapi/src/index.ts:20:63) {
  loc: { start: { line: 1, column: 23 } },
  codeFrame: '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 1 |\x1B[39m \x1B[36mimport\x1B[39m { type api \x1B[36mas\x1B[39m  } \x1B[36mfrom\x1B[39m \x1B[32m"../tools/generated-api/base-api"\x1B[39m\x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m   |\x1B[39m                       \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 2 |\x1B[39m \x1B[36mconst\x1B[39m injectedRtkApi \x1B[33m=\x1B[39m api\x1B[33m.\x1B[39minjectEndpoints({\x1B[0m\n' +
    '\x1B[0m \x1B[90m 3 |\x1B[39m     endpoints\x1B[33m:\x1B[39m build \x1B[33m=>\x1B[39m ({\x1B[0m\n' +
    '\x1B[0m \x1B[90m 4 |\x1B[39m         get___\x1B[33m:\x1B[39m build\x1B[33m.\x1B[39mquery\x1B[33m<\x1B[39m\x1B[33mGet___ApiResponse\x1B[39m\x1B[33m,\x1B[39m \x1B[33mGet___ApiArg\x1B[39m\x1B[33m>\x1B[39m({\x1B[0m'
}

(The parts replaced with ___ are specific API endpoint names)

Note this bit

> 1 | import { type api as  } from "../tools/generated-api/base-api";
    |                       ^

The missing alias is there both in the @rtk-incubator/rtk-query-codegen-openapi version that does not provide an API at all (only a custom query), and in the @rtk-query/codegen-openapi version no matter what I make the config values (I tried making the exportName of the API file become api, or something else other than api, and the result is the same).

I’m sure it happened in the past due to some dependency issue, but I cannot remember the details.

Is anyone else seeing this?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Meligycommented, Aug 29, 2022

I’m not seeing this issue with TS 4.8 final (tested with 4.8.2), so, closing this issue.

Thanks a lot for reply here and on Twitter.

0reactions
Meligycommented, Aug 7, 2022

Are we saying that this is actually working in the PR or other places that have TS 4.8?

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Guide to OpenAPI Code Generation for TypeScript
In this article article I explain how to automatically generate the client code for a REST API. The basic idea is to specify...
Read more >
Generating HTTP API clients using Visual Studio Connected ...
Visual Studio Connected Services can generate .NET client code directly from an OpenAPI spec. Learn how to build great HTTP clients quickly!
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
Read more >
openapi-typescript-codegen - npm
Library that generates Typescript clients based on the OpenAPI specification.. Latest version: 0.23.0, last published: 7 months ago.
Read more >
JSDoc Reference - TypeScript: Documentation
The meaning is usually the same, or a superset, of the meaning of the tag given at jsdoc.app. The code below describes the...
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