75 lines
1.7 KiB
Text
75 lines
1.7 KiB
Text
|
==== tests/cases/compiler/returnInConstructor1.ts (4 errors) ====
|
||
|
class A {
|
||
|
foo() { }
|
||
|
constructor() {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class B {
|
||
|
foo() { }
|
||
|
constructor() {
|
||
|
return 1; // error
|
||
|
~
|
||
|
!!! Return type of constructor signature must be assignable to the instance type of the class
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class C {
|
||
|
foo() { }
|
||
|
constructor() {
|
||
|
return this;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class D {
|
||
|
foo() { }
|
||
|
constructor() {
|
||
|
return "test"; // error
|
||
|
~~~~~~
|
||
|
!!! Return type of constructor signature must be assignable to the instance type of the class
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class E {
|
||
|
public foo: number;
|
||
|
constructor() {
|
||
|
return { foo: 1 };
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class F {
|
||
|
public foo: string;
|
||
|
constructor() {
|
||
|
return { foo: 1 }; //error
|
||
|
~~~~~~~~~~
|
||
|
!!! Return type of constructor signature must be assignable to the instance type of the class
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class G {
|
||
|
private test: number;
|
||
|
public test1() { }
|
||
|
foo() { }
|
||
|
constructor() {
|
||
|
this.test = 2;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class H extends F {
|
||
|
constructor() {
|
||
|
super();
|
||
|
return new G(); //error
|
||
|
~~~~~~~
|
||
|
!!! Return type of constructor signature must be assignable to the instance type of the class
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class I extends G {
|
||
|
constructor() {
|
||
|
super();
|
||
|
return new G();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|