openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

Type errors in `vue-query.gen.ts`

Open zumm opened this issue 1 year ago • 5 comments

Description

I'm trying to use @tanstack/vue-query plugin, but getting type errors with infinite queries and mutations.

For infinite queries:

The inferred type of 'getMyHistoryInfiniteOptions' references an inaccessible 'unique symbol' type. A type annotation is necessary.ts(2527)
The inferred type of 'getMyHistoryInfiniteOptions' cannot be named without a reference to 'node_modules/.pnpm/@[email protected]/node_modules/@tanstack/query-core/build/modern/hydration-mKPlgzt9'. This is likely not portable. A type annotation is necessary.ts(2742)

For mutations:

The inferred type of 'readFeedVideosMutation' cannot be named without a reference to 'node_modules/.pnpm/@[email protected]/node_modules/@tanstack/query-core/build/modern/hydration-mKPlgzt9'. This is likely not portable. A type annotation is necessary.ts(2742)

My config:

import { defineConfig } from '@hey-api/openapi-ts'

export default defineConfig({
  experimentalParser: true,
  client: '@hey-api/client-fetch',
  input: 'src/api-client/openapi.yml',
  output: 'src/api-client',
  plugins: [
    '@tanstack/vue-query',
    {
      dates: true,
      name: '@hey-api/transformers',
    },
  ],
})

Reproducible example or configuration

No response

OpenAPI specification (optional)

openapi: 3.0.1

components:
  schemas:
    OK:
      type: object
      properties:
        ok:
          type: boolean
    Error:
      type: object
      properties:
        error:
          type: string
    Video:
      type: object
      required:
        - id
        - title
        - description
        - url
        - publishedAt
        - channelId
        - channelTitle
        - channelUrl
        - duration
        - commentCount
        - likeCount
        - viewCount
      properties:
        id:
          type: string
        title:
          type: string
        description:
          type: string
        url:
          type: string
        publishedAt:
          type: string
          format: date-time
        categoryId:
          type: string
        channelId:
          type: string
        channelTitle:
          type: string
        channelUrl:
          type: string
        duration:
          type: string
        commentCount:
          type: integer
          format: uint64
        likeCount:
          type: integer
          format: uint64
        viewCount:
          type: integer
          format: uint64
        thumbnails:
          $ref: '#/components/schemas/Thumbnails'
    Channel:
      type: object
      required:
        - id
        - title
        - description
        - url
        - commentCount
        - subscriberCount
        - videoCount
        - viewCount
      properties:
        id:
          type: string
        title:
          type: string
        description:
          type: string
        url:
          type: string
        subscriberCount:
          type: integer
          format: uint64
        commentCount:
          type: integer
          format: uint64
        videoCount:
          type: integer
          format: uint64
        viewCount:
          type: integer
          format: uint64
        thumbnails:
          $ref: '#/components/schemas/Thumbnails'
    Thumbnails:
      type: object
      properties:
        default:
          $ref: '#/components/schemas/Thumbnail'
        medium:
          $ref: '#/components/schemas/Thumbnail'
        high:
          $ref: '#/components/schemas/Thumbnail'
        standard:
          $ref: '#/components/schemas/Thumbnail'
        maxres:
          $ref: '#/components/schemas/Thumbnail'
    Thumbnail:
      type: object
      required:
        - url
        - width
        - height
      properties:
        url:
          type: string
        width:
          type: integer
        height:
          type: integer

paths:
  /my/history:
    get:
      summary: My history
      operationId: getMyHistory
      parameters:
        - name: offset
          in: query
          required: false
          schema:
            type: integer
        - name: count
          in: query
          required: true
          schema:
            type: integer
            default: 10
            minimum: 1
            maximum: 100
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                additionalProperties:
                  type: array
                  items:
                    $ref: '#/components/schemas/Video'
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /feed/videos/read:
    post:
      operationId: readFeedVideos
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - ids
              properties:
                ids:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OK'
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

System information (optional)

@hey-api/client-fetch: 0.5.0 @hey-api/openapi-ts: 0.57.1

zumm avatar Nov 26 '24 11:11 zumm

Hi @zumm, would you be able to replicate this in StackBlitz?

mrlubos avatar Dec 02 '24 16:12 mrlubos

Seems like enabled compilerOptions.composite option in my tsconfig.json file causes this issue. I guess it was enabled by old vue@create template. There is no such option in newest template, so i just disabled it in my projects.

I don't know why it causes problem tho. If someone wants to test it, here is minimal tsconfig.json (depends on @vue/tsconfig):

{
  "extends": "@vue/tsconfig/tsconfig.dom.json",
  "compilerOptions": {
    "composite": true,
    "baseUrl": ".",
  },
  "include": ["api/**/*"],
  "exclude": []
}

zumm avatar Jan 09 '25 10:01 zumm

@zumm I'll try to recreate, thanks for figuring it out! I've had this tab open in my browser for a while, just didn't have time to get to it yet

mrlubos avatar Jan 09 '25 10:01 mrlubos

@mrlubos I think this issue isn't relevant to openapi-ts itself, just consequence of weird interaction between pnpm and typescript. But if you want to investigate this issue a bit farther here is stackblitz reproduction.

zumm avatar Jan 09 '25 13:01 zumm

@zumm try with the latest (v0.66.4) if you'd see a reduction in errors?

mrlubos avatar Apr 13 '25 23:04 mrlubos