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

question[TypeScript] How should AggregateError be imported as type when using TypeScript without esModuleInterop option #14

Closed
oscard0m opened this issue Sep 17, 2020 · 5 comments

Comments

@oscard0m
Copy link

When trying to use AggregateError as type in a Typescript project the following issue happens:
image

Conditions

  • To not use esModuleInterop in tsconfig.json

Tried alternatives

image
(this would not fit the purpose of getting the type)


image
(it implies enabling moduleInterop flag)


image

Question

Considering the way this library is exposing AggregateError, Is there a way to import AggregateError in a ESModule way as Typescript type (so, no const AggreagateError = require('aggregate-error') and without enabling esModuleInterop option?

Details

You can find more details in:

@sindresorhus
Copy link
Owner

This is not the place to ask for general TypeScript support.

@sindresorhus
Copy link
Owner

Considering the way this library is exposing AggregateError, Is there a way to import AggregateError in a ESModule way as Typescript type (so, no const AggreagateError = require('aggregate-error') and without enabling esModuleInterop option?

I don't think that's possible, no. That is indeed a weird limitation though. I would have expected import type AggreagateError = require('aggregate-error') to work. I would bring this up with the TS team.

@oscard0m
Copy link
Author

Considering the way this library is exposing AggregateError, Is there a way to import AggregateError in a ESModule way as Typescript type (so, no const AggreagateError = require('aggregate-error') and without enabling esModuleInterop option?

I don't think that's possible, no. That is indeed a weird limitation though. I would have expected import type AggreagateError = require('aggregate-error') to work. I would bring this up with the TS team.

You are totally right. Sorry for "spamming" issues here. I will address this question to the proper TypeScript channel.

Thanks for your attention and support ❤️

@gr2m
Copy link
Contributor

gr2m commented Sep 18, 2020

@sindresorhus the current CommonJS-style export makes aggregate-error hard to consume for ES Module-style libraries such as all the @octokit/* modules. Every consumer of e.g. @octokit/webhooks will have to add skipLibCheck: true to their TSConfig settings, there is nothing on our side that we can do.

A workaround was kindly suggested by @smockle via https://github.com/smockle/aggregate-error-test/: but it requires us to override aggregate-error's type definitions, which puts the burden on us to keep it up-to-date with the implementation.

I understand the change was done here: #9 which I think references sindresorhus/p-cancelable#19, but I don't see the reason why you decided to make that change? Is there a discussion somewhere that I can learn more about your reasoning?

@gr2m
Copy link
Contributor

gr2m commented Sep 18, 2020

Update: I've found sindresorhus/memoize#31 (comment) (thanks @smockle)

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

3 participants