Giter VIP home page Giter VIP logo

Comments (8)

fasttime avatar fasttime commented on June 18, 2024

Thanks for the report. You may be able to solve this by setting the target compiler option to "ES2015" or preferably "ES2020" in your tsconfig.json. Newer versions of @angular/cli have this set by default when a project is created with ng new.

{
  "compilerOptions": {
    ...
    "target": "es2015",
    ...
  }
}

Without that setting TypeScript will transpile Polytype to ES3, which doesn't work well for a number of reasons. Granted, the error message could be better.

from polytype.

st-clair-clarke avatar st-clair-clarke commented on June 18, 2024

I was using es5. I have changed it to es2020 but that caused other issues. I made both the target and the lib in tsconfig the same - es2017- and everything seems fine now. Thanks

from polytype.

st-clair-clarke avatar st-clair-clarke commented on June 18, 2024

Although the app runs with the above tsconfig specs, it will not build - it only builds with 'target': es5 - but this then is not compatible with your package. I am in a bind because of these two things. The failure to build with the above specs is not due to your package - it seems to be a more generalised problem with angular. If you find a solution please let me know, because this will also impact the use of your package.

By the way transpilation is to es5 in my case, not es3.

from polytype.

fasttime avatar fasttime commented on June 18, 2024

Actually Angular 9 should be fine with any JS target version, but you may need to change other settings, too.

It is also possible that some dependencies involved in the build process don't support ES6.
If you can spot which one they are, maybe from some error message, you may be able to update or replace them.

Another option is to import/include Polytype as an external dependency rather than have it bundled with the rest of the code. If you can do it you could keep targeting ES5 in TypeScript and copy the Polytype package folder unchanged into your dist folder.

Finally, if ES5 is required for compatibility with old browsers, then Polytype may not be the right tool for you. In this case mixins may be a more appropriate choice.

This is very generic advice but it's all I can think of without more detailed info, and porting Polytype to ES5 is not an option. Please, let me know if you manage to solve your problem in a way or another.

from polytype.

fasttime avatar fasttime commented on June 18, 2024

The problem is that the call to super() gets transpiled by TypeScript into Object.apply(...). But ES6 constructors require constructor semantics to be invoked (new ...).

If you know the arguments passed to every base constructor in advance, you can use a wrapper around the call to classes to enforce a new expression. In your example:

const PolyTypesComponentBase = classes(Utils);
const WrapPolyTypesComponentBase =
function () { return new PolyTypesComponentBase; } as unknown as typeof PolyTypesComponentBase;

...
export class PolyTypesComponent extends WrapPolyTypesComponentBase implements OnInit {

I'd call this a kind of a transpiler hack. It works as long as no additional functionality is needed.

from polytype.

st-clair-clarke avatar st-clair-clarke commented on June 18, 2024

from polytype.

fasttime avatar fasttime commented on June 18, 2024

Does it work with your old config with "target": "es5"?

from polytype.

fasttime avatar fasttime commented on June 18, 2024

Polytype 0.10 will fail to load if the module is transpiled to ES5 or ES3 code, and will throw an error with a message describing the problem instead. I'm going to close this issue by now. Let me know if you need more help.

from polytype.

Related Issues (14)

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.