Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Error with @hey-api/openapi-ts Generated Files #1746

Open
fradal64 opened this issue Feb 25, 2025 · 6 comments
Open

TypeScript Error with @hey-api/openapi-ts Generated Files #1746

fradal64 opened this issue Feb 25, 2025 · 6 comments
Labels
bug 🔥 Something isn't working

Comments

@fradal64
Copy link

fradal64 commented Feb 25, 2025

Description

I am encountering a TypeScript error when generating files with openapi-ts. The error message is as follows:

Property 'client' does not exist on type 'Options<GetCurrentUserData, ThrowOnError>'.ts(2339)

Here is an example of one of the automatically generated code snippets causing the error:

export const getCurrentUser = <ThrowOnError extends boolean = false>(options?: Options<GetCurrentUserData, ThrowOnError>) => { return (options?.client ?? client).get<GetCurrentUserResponse, unknown, ThrowOnError>({ security: [ { scheme: 'bearer', type: 'http' } ], url: '/api/auth/users/me', ...options }); };

@fradal64 fradal64 added the bug 🔥 Something isn't working label Feb 25, 2025
@mrlubos
Copy link
Member

mrlubos commented Feb 25, 2025

@fradal64 Did you ensure your client is updated to the latest (or correct) version?

@nash15963
Copy link

I encountered the same issue initially, but updating my version resolved it.

    "@hey-api/client-axios": "^0.6.1",
    "@hey-api/openapi-ts": "^0.64.5",

Please make sure you are using the latest version.

@fradal64
Copy link
Author

I had in fact outdated versions but now that I have updated them I still get the same error. These are the new versions I have installed.

"@hey-api/openapi-ts": "^0.64.5"
"@hey-api/client-axios": "^0.6.1",
"@hey-api/client-fetch": "^0.8.1",

@mrlubos
Copy link
Member

mrlubos commented Feb 26, 2025

@fradal64 please share a reproducible example and I can have a look

@fradal64
Copy link
Author

@mrlubos thank you so much. I have tried to regenerate the client folder after upgrading to the latest versions of the packages and now I get the following error:

🚫 client needs to be set to generate SDKs - which HTTP client do you want to use?
Error: 🚫 client needs to be set to generate SDKs - which HTTP client do you want to use?
    at Object.pluginByTag (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:15:59170)
    at Object._infer (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:15:5665)
    at i (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:15:59249)
    at Jf (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:15:59342)
    at Yf (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:15:59960)
    at /home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:15:61230
    at Array.map (<anonymous>)
    at tc (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:15:60518)
    at async oj (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/dist/index.cjs:1311:4380)
    at async start (/home/lg519/Projects/Parts_Finder_Project/frontend/node_modules/@hey-api/openapi-ts/bin/index.cjs:120:21)

Here is my main file where I set the client:

import App from '@/App.tsx'
import { client } from '@/client/sdk.gen.ts'
import { AuthProvider } from '@/contexts/auth-context'
import { WebSocketProvider } from '@/contexts/websocket-context'
import '@/index.css'
import { clearAuthToken, getAuthToken } from '@/lib/auth.ts'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import axios from 'axios'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'

// Initialize React Query client
const queryClient = new QueryClient()

// Initialize Axios client
client.setConfig({
  baseURL: import.meta.env.VITE_API_URL,
  auth: () => getAuthToken() ?? '',
})

client.instance.interceptors.response.use(
  (response) => response,
  (error) => {
    if (axios.isAxiosError(error) && error.response?.status === 401) {
      clearAuthToken();
      if (!window.location.pathname.startsWith('/login')) {
        window.location.href = '/login';
      }
      return Promise.reject(new Error('Session expired'));
    }
    return Promise.reject(error);
  }
)

createRoot(document.getElementById('root')!).render(
  <StrictMode>
    <QueryClientProvider client={queryClient}>
      <AuthProvider>
        <WebSocketProvider>
          <App />
        </WebSocketProvider>
      </AuthProvider>
    </QueryClientProvider>
  </StrictMode>,
)

This used to work fine with the previous versions of the package but now it isn't working anymore.

@mrlubos
Copy link
Member

mrlubos commented Feb 26, 2025

@fradal64 I suspect you didn't look at the migration notes 🤠 https://heyapi.dev/openapi-ts/migrating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants