aws4-axios icon indicating copy to clipboard operation
aws4-axios copied to clipboard

Can't compile in an es6 typescript project

Open horrendo opened this issue 1 year ago • 1 comments

This is quite likely due to my inexperience with es6, but I'm in the process of migrating a typescript project from commonjs to es6, and I'm stuck.

I've created a small test case at https://github.com/horrendo/aws4-test. The README shows the error I'm getting. It also shows a workaround which I'd like to avoid if possible.

I'd appreciate any help.

Thanks !!

horrendo avatar Dec 25 '23 21:12 horrendo

This issue is a bit old, but I want to chime in that I have the same issue when compiling an ESM library that is dependent on aws4-axios.

The error I receive is identical to what @horrendo reports in his github repo:

error TS2345: Argument of type '(config: InternalAxiosRequestConfig<any>) => Promise<InternalAxiosRequestConfig<any>>' is not assignable to parameter of type '(value: InternalAxiosRequestConfig<any>) => InternalAxiosRequestConfig<any> | Promise<InternalAxiosRequestConfig<any>>'.
  Types of parameters 'config' and 'value' are incompatible.
    Type 'import("{RedactedAbsolutePath}/node_modules/axios/index", { with: { "resolution-mode": "import" } }).InternalAxiosRequestConfig<any>' is not assignable to type 'import("{RedactedAbsolutePath}/node_modules/axios/index").InternalAxiosRequestConfig<any>'.
      Types of property 'headers' are incompatible.
        Type 'import("{RedactedAbsolutePath}/node_modules/axios/index", { with: { "resolution-mode": "import" } }).AxiosRequestHeaders' is not assignable to type 'import("{RedactedAbsolutePath}/node_modules/axios/index").AxiosRequestHeaders'.
          Type 'AxiosRequestHeaders' is not assignable to type 'Partial<RawAxiosHeaders & { "Content-Length": AxiosHeaderValue; "Content-Encoding": AxiosHeaderValue; Accept: AxiosHeaderValue; "User-Agent": AxiosHeaderValue; Authorization: AxiosHeaderValue; } & { ...; }>'.
            Types of property '"Content-Length"' are incompatible.
              Type 'import("{RedactedAbsolutePath}/node_modules/axios/index", { with: { "resolution-mode": "import" } }).AxiosHeaderValue | undefined' is not assignable to type 'import("{RedactedAbsolutePath}/node_modules/axios/index").AxiosHeaderValue | undefined'.
                Type 'AxiosHeaders' is not assignable to type 'AxiosHeaderValue | undefined'.
                  Type 'AxiosHeaders' is missing the following properties from type 'string[]': length, pop, push, join, and 33 more.

Also pulled from @horrendo 's link, the solution of casting the interceptor solved the typing issue for me:

Making this change resolves the compilation error.

from:

axios.interceptors.request.use(interceptor);

to:

axios.interceptors.request.use(<any>interceptor);

michaelj-smith avatar Aug 08 '24 17:08 michaelj-smith