Comments (8)
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.
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.
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.
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.
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.
from polytype.
Does it work with your old config with "target": "es5"
?
from polytype.
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)
- explicit classes export HOT 2
- Bind methods problem HOT 5
- Abstract Class Support HOT 2
- Documentation update
- Comparing polytype with other methods
- Using generic in baseclass HOT 17
- Improving typing for getPrototypeListOf HOT 1
- Method override does not work correctly with "crocks" library HOT 2
- Issue with Angular module HOT 3
- Issue with Angular 8 in prod mode HOT 3
- Issue with ngOnDestry method when use polytype HOT 2
- polytype extended class properties not behaving as typescript extended class propeties HOT 2
- empty catch block - not accepted by some linters 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 polytype.