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

Can't compile in an es6 typescript project #1251

Open
horrendo opened this issue Dec 25, 2023 · 1 comment
Open

Can't compile in an es6 typescript project #1251

horrendo opened this issue Dec 25, 2023 · 1 comment

Comments

@horrendo
Copy link

horrendo commented Dec 25, 2023

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 horrendo changed the title Can't compile in an es6 project Can't compile in an es6 typescript project Dec 28, 2023
@michaelj-smith
Copy link

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants