-
Notifications
You must be signed in to change notification settings - Fork 83
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
fix(typescript): aggregator-error imported properly #248
fix(typescript): aggregator-error imported properly #248
Conversation
@wolfy1339 @gr2m I will need some help here, seems like we have an incompatibility issue when importing aggregate-error type on Any idea on how can we bypass this? |
@@ -1,4 +1,4 @@ | |||
import type AggregateError from "aggregate-error"; | |||
import AggregateError = require("aggregate-error"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the syntax recommended by the test action?
import * as ns from "mod"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying this approach I get the following error:
Also, trying import AggregateError from ...
seems to be an issue:
The reason I was using import AggregateError = require()
is because what I found in Typescript docs: https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require but not sure how to handle this.
Any ideas @wolfy1339
@@ -1,11 +1,11 @@ | |||
{ | |||
"compilerOptions": { | |||
"esModuleInterop": true, | |||
"module": "esnext", | |||
"module": "commonjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't be targetting commonjs
, Pika does that for us.
If you use the syntax i commented above, then you don't need to use the TS import = require()
The This is so odd. Maybe we could research how other TypeScript projects are using |
The problem here is that we are using ES Modules, and AggregateError is using CommonJS. Normally, under regular plain JS using ES Modules, using the following syntax works fine import * as AggregateError from 'aggregate-error' However, in TypeScript, one needs to enable the There's also the "Synthetic default import" mode in TypeScript ( import AggregateError from 'aggreagate-error' This unfortunately, has nothing to do with upstream. It's a problem/feature of TS |
If this particular library is such a trouble, we could just copy/paste the source code, it's ~40LOC: https://github.com/sindresorhus/aggregate-error/blob/master/index.js and two small dependencies that we could replace or remove if necessary |
Before opting for this I would like to check how other dependents of this package are importing it and which |
Hey, just a followup on this topic. I just researched on several dependents from I just posted a question to I did a quick research on StackOverflow on this but I did not find a specific topic on this. Do you think it would be interesting to post the question there? |
Thank you for the research @dominguezcelada. I'd suggest we do a local override of the types, as @smockle suggests here: Maybe we can make the override more explicit, by calling the folder |
Actually nevermind, let's just go ahead and remove the dependency altogether, and instead move the whole aggregate-error source code into I hope that TypeScript will fix the problem on the tooling side, at which point we will be able to remove the workaround |
Sounds good to me. I will take care on getting some assistance with TypeScript and followup on this. |
For what I've read on the thread discussion @gr2m shared and as DefinetelyTyped suggests, we are tied to how If we want to use So... here the solutions would be (or at least what I found):
|
It's also possible that the problem gets resolved within TypeScript π€πΌ Lets move forward with #270 and hope for the best |
resolved by #270 |
π Summary
To apply proper import when using
aggregate-error
typeβ± Motivation and Context
Fix #245
π How Has This Been Tested?
Running
tsc
worksBefore
After
But when running
npm run build
(pika) does not:π References:
https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require