Comments (11)
What if we export a default
entry? Would TypeScript be able to load it using import asyncPool from 'tiny-async-pool';
?
In order not to break API, we can export both the function and a default
export. Please, let me know if that works for you.
from async-pool.
I'm actually not sure if that would fix it.
Additionally I actually brought it up because named imports are more declarative and easier to understand and extend. And API breakage would simply mean a new major release which would not impact current users of version 1.x.
from async-pool.
easier to understand
Debatable because it's subjective :)
easier to extend
Agreed, but then we make a major bump.
I'm actually not sure if that would fix it.
If you are interested in testing this out, one easy test you could do in your end (please) before I change things here is to update your locally installed async-pool
package with the following:
diff --git a/dist/node.js b/dist/node.js
index 050965d..58a53d0 100644
--- a/dist/node.js
+++ b/dist/node.js
@@ -8,3 +8,4 @@ if (semver.satisfies(process.version, "<8")) {
}
module.exports = exports;
+module.exports.default = exports;
from async-pool.
With this change I had to change the definition to export default function asyncPool
instead of
export = asyncPool;
declare function asyncPool(/* ... *) {
/* ... */
}
It results in the following import:
import asyncPool from 'tiny-async-pool';
from async-pool.
Let's do that update? I understood it looks better for you on TypeScript, although it's not exactly what you wanted (named exports). Do you want to submit a PR? Thanks
from async-pool.
If you'd like it that way - sure!
from async-pool.
Fixed by #6
from async-pool.
Would you reconsider this after checking out the related discucssion at DefinitelyTyped?
from async-pool.
@krlwlfrt thanks for the TypeScript integration work you're doing.
It seems like in TypeScript you always have to use export =
and import =
if dealing with CommonJS module.exports except if --esModuleInterop
or -allowSyntheticDefaultImports
is used in user end (link), correct?
It's not clear to me what could be reconsidered? Even if using a named export such as module.exports = {asyncPool}
, it would still require the use of export =
, import =
, doesn't it?
That being said, what do you think about this... Currently, package.json "main"
points to "dist/node.js"
which uses commonJS module exports. We need a separate file using ES modules export (i.e., export default ...
) that you can use in TypeScript. Is there a TypeScript way to override the "main"
property in package.json?
from async-pool.
No. The section that you're referring to only describes what happens with exports =
and exports.default
.
Named export would result in a TypeScript definition with export function asyncPool
.
This would enable an import like import {asyncPool} from
tiny-async-pool`.
As far as I know, there is no option do override the main file in Node.js since TypeScript does support different module systems but no other specifics of the platforms it runs on.
from async-pool.
@rxaviers, I'd open a PR with the appropriate changes if you'd like.
from async-pool.
Related Issues (20)
- how to kill this XD HOT 3
- don't throw on empty array HOT 5
- Readability issue HOT 2
- Deno support HOT 1
- Typescript bindings HOT 4
- Chrome fails (Uncaught (in promise) TypeError: Failed to fetch) HOT 1
- another args to function HOT 1
- Failed to process the request HOT 3
- why using "array" as an input for iteratorFn() HOT 4
- Promise.allSettled() instead of Promise.all() option HOT 9
- question) How can i execute function with multiple arguments? HOT 1
- Benchmarks, overhead information HOT 1
- Unhandled rejections in some corner case HOT 2
- your code amazing!
- Allow for 1.x style await, without having to use for await HOT 9
- Feature: guarantee order of results HOT 3
- Does not "yield" reliably
- README.md usage issue HOT 2
- Allow iterable to be an async-iterable / async-generator HOT 2
- Add documentation about ordering no longer being preserved HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-pool.