-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Build error: TS2345: Argument of type 'ApiResult<any>' is not assignable to parameter of type 'T | PromiseLike<T>'. #95
Comments
Is this a new issue, did this work in previous versions? |
I replicated the issue, and it seems to be an issue when using Axios and the base-generated (non-provided) request file from the underlying service generator @hey-api/openapi-ts We need to create a ticket and reproducible example with @hey-api/openapi-ts. 2 workarounds I can think of:
// request.ts file
/* eslint-disable */
// @ts-nocheck
import axios from "axios";
import type { RawAxiosRequestHeaders } from "axios";
import type { ApiRequestOptions } from "./ApiRequestOptions";
import { CancelablePromise } from "./CancelablePromise";
import type { OpenAPIConfig } from "./OpenAPI";
// Optional: Get and link the cancelation token, so the request can be aborted.
const source = axios.CancelToken.source();
const axiosInstance = axios.create({
// Your custom Axios instance config
baseURL: "http://localhost:4010",
headers: {
// Your custom headers
} satisfies RawAxiosRequestHeaders,
});
// Add a request interceptor
axiosInstance.interceptors.request.use(
function (config) {
// Do something before request is sent
if (!config.url || !config.params) {
return config;
}
Object.entries<any>(config.params).forEach(([key, value]) => {
const stringToSearch = `{${key}}`;
if(config.url !== undefined && config.url.search(stringToSearch) !== -1) {
config.url = config.url.replace(`{${key}}`, encodeURIComponent(value));
delete config.params[key];
}
});
return config;
},
function (error) {
// Do something with request error
return Promise.reject(error);
}
);
// Add a response interceptor
axiosInstance.interceptors.response.use(
function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
},
function (error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
}
);
export const request = <T>(
config: OpenAPIConfig,
options: ApiRequestOptions
): CancelablePromise<T> => {
return new CancelablePromise((resolve, reject, onCancel) => {
onCancel(() => source.cancel("The user aborted a request."));
let formattedHeaders = options.headers as RawAxiosRequestHeaders;
if (options.mediaType) {
formattedHeaders = {
...options.headers,
"Content-Type": options.mediaType,
} satisfies RawAxiosRequestHeaders;
}
return axiosInstance
.request({
url: options.url,
data: options.body,
method: options.method,
params: options.path,
headers: formattedHeaders,
cancelToken: source.token,
})
.then((res) => {
resolve(res.data);
})
.catch((error) => {
reject(error);
});
});
}; |
I don't know, it's my first time using the project.
This leads to the same issue:
|
I am also getting this error with |
The underlying service generator changed its defaults. We now need to pass a setting to generate the same response. Providing the I opened a PR to set the default value to @lavocatt and @pradel, thank you for opening the issue and helping debug. use the following in the meantime until the new version of this library is released. npx --package @7nohe/openapi-react-query-codegen openapi-rq -i ./api-server/config/openapi.yml -c axios -o src/openapi/jolokia --serviceResponse body |
New version is released. |
Describe the bug
There's an issue building the generated code.
To Reproduce
npx --package @7nohe/openapi-react-query-codegen openapi-rq -i ./api-server/config/openapi.yml -c axios -o src/openapi/jolokia
Upon building:
OpenAPI spec file
https://github.com/artemiscloud/activemq-artemis-self-provisioning-plugin/blob/main/api-server/config/openapi.yml
tsconfig
eslint config
Expected behavior
no compilation error
The text was updated successfully, but these errors were encountered: