How to fix error: Multiple constructor implementations are not allowed


#1

when i want to build:

ionic cordova build --release android

i get the following error message:

Multiple constructor implementations are not allowed.

l27: constructor(public navCtrl: NavController, public http: HttpClient) {

-> how can i fix this? thx :slight_smile:


#2

How about by having only one constructor for that class?


#3

This. Multiple/overloading constructors is common practice in Java applications but not so much in Typescript. In fact I have never seen it done via typescript and am not sure why it would be.

Even if there is a good reason, looks like it leads to a dead end


#4

Because it’s impossible. JavaScript does not have runtime type information, so function overloading (including constructors) cannot be done. Arguments are not part of a function’s signature.


#5

That’s a pretty solid reason for avoiding the practice. And a great explanation for why an error would be thrown in the process.

Also a good example of the deceptive similarities between TypeScript and Java. At this point I’m writing mostly in Java and can say there are few similarities despite appearances.