Closed
Description
TypeScript Version: 3.5.0-dev.20190418
Search Terms: typescript quoted constructor
Code
class Foo {
constructor(name: string) {
this.name = name
}
}
class Bar {
"constructor"(name: string) {
this.name = name
}
}
new Foo("hello")
new Bar("hello")
Expected behavior:
Compiles without error
Actual behavior:
The new Foo
call compiles properly, but the new Bar
call produces a type checking error:
test.ts:9:9 - error TS2554: Expected 0 arguments, but got 1.
9 new Bar("hello")
~~~~~~~
Note that running the code (with the type assertions stripped) results in both constructors being called, but TypeScript’s ES5 transpilation instead sets the second constructor as a method named constructor
, which causes it not to be run.
Playground Link: Open playground
Related Issues: Encountered in prettier/prettier#6063.