Git Product home page Git Product logo

Comments (10)

DylanPiercey avatar DylanPiercey commented on May 31, 2024 3

Just because they do doesn’t mean that this wouldn’t be a good change. This does nothing for browserify users or people using older versions of webpack.

This solution is both relatively easy to switch to and the support is guaranteed.

from tslib.

DylanPiercey avatar DylanPiercey commented on May 31, 2024 2

I am also finding this to be a problem when publishing many small typescript modules. Ideally each utility would have it's own namespace require('tslib/$NAME').

Inlining the code directly means (when publishing a bunch of small modules) a bunch of code is duplicated, however when you use importHelpers it means you are incurring at least 2kb gzipped, which is a lot to ask for a module that is say 1kb gzipped.

I would personally advocate the approach taken by just however everything doesn't necessarily need to be in it's own published package.


It would be even cooler if these utilities could be used (without risk and with official support) in non typescript files to even further decrease duplication. For example in many of modules I require something like just-extend when I could easily use tslib.__extends if it were supported.

from tslib.

streamich avatar streamich commented on May 31, 2024 1

So you are importing the whole tslib there.

Again, why not put each helper in its own module and do something like this:

var _extends = require("tslib/lib/extends");

from tslib.

streamich avatar streamich commented on May 31, 2024 1

Honestly, there is not a lot of code in this library. While the output does not lend itself to tree-shaking, your loader will only include it once so it doesn't seem like a code size issue.

@aluanhaddad "a lot of code" is relative, if I write a 10 line script for the web that uses only _extends, why would I incur a penalty of 200-line tslib.

from tslib.

lmk123 avatar lmk123 commented on May 31, 2024

First, install tslib:

npm install tslib

Then add importHelpers: true in your tsconfig.json:

{
  "compilerOptions": {
    "moduleResolution": "node",
    "module": "commonjs",
    "target": "es5",
    // ...
    "importHelpers": true // <-------
  }
}

Now when you compiler *.ts file, it may looks like this:

var tslib_1 = require("tslib")

tslib_1.__awaiter(...)

tslib_1.__extends(...)

from tslib.

aluanhaddad avatar aluanhaddad commented on May 31, 2024

Honestly, there is not a lot of code in this library. While the output does not lend itself to tree-shaking, your loader will only include it once so it doesn't seem like a code size issue.

Also, some of the functions reference each other, meaning that if the package were split, they would need cross referencing imports which would result in a more complex multi-module format export strategy than what is already in place.

from tslib.

frankwallis avatar frankwallis commented on May 31, 2024

@streamich if you don't use importHelpers then typescript will inline only the methods which you actually use. importHelpers is to reduce helper methods being inlined across multiple modules.

from tslib.

streamich avatar streamich commented on May 31, 2024

@frankwallis I know that, but it will inline those in each file though.

from tslib.

DanielRosenwasser avatar DanielRosenwasser commented on May 31, 2024

Is there a reason that existing bundlers can't just do a good job here with tree-shaking? We provide both ES2015 and UMD outputs. Both Webpack and Rollup should be able to do a decent job here.

from tslib.

orta avatar orta commented on May 31, 2024

Yeah, I'm against the idea of splitting this into sub-modules too. Module bundlers can handle tree shaking tslib just fine nowadays (we have tests for in in #126).

I'm going to close 👍🏻

from tslib.

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.