Giter Club home page Giter Club logo

Comments (11)

rxaviers avatar rxaviers commented on July 18, 2024

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.

krlwlfrt avatar krlwlfrt commented on July 18, 2024

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.

rxaviers avatar rxaviers commented on July 18, 2024

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.

krlwlfrt avatar krlwlfrt commented on July 18, 2024

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.

rxaviers avatar rxaviers commented on July 18, 2024

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.

krlwlfrt avatar krlwlfrt commented on July 18, 2024

If you'd like it that way - sure!

from async-pool.

rxaviers avatar rxaviers commented on July 18, 2024

Fixed by #6

from async-pool.

krlwlfrt avatar krlwlfrt commented on July 18, 2024

Would you reconsider this after checking out the related discucssion at DefinitelyTyped?

from async-pool.

rxaviers avatar rxaviers commented on July 18, 2024

@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.

krlwlfrt avatar krlwlfrt commented on July 18, 2024

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.

krlwlfrt avatar krlwlfrt commented on July 18, 2024

@rxaviers, I'd open a PR with the appropriate changes if you'd like.

from async-pool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.