mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
78 lines
3.5 KiB
Plaintext
78 lines
3.5 KiB
Plaintext
derivedGenericClassWithAny.ts(2,5): error TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor.
|
|
derivedGenericClassWithAny.ts(3,18): error TS2322: Type 'null' is not assignable to type 'T'.
|
|
'T' could be instantiated with an arbitrary type which could be unrelated to 'null'.
|
|
derivedGenericClassWithAny.ts(5,9): error TS2322: Type 'null' is not assignable to type 'T'.
|
|
'T' could be instantiated with an arbitrary type which could be unrelated to 'null'.
|
|
derivedGenericClassWithAny.ts(29,5): error TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor.
|
|
derivedGenericClassWithAny.ts(30,18): error TS2322: Type 'string' is not assignable to type 'T'.
|
|
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
|
|
derivedGenericClassWithAny.ts(32,9): error TS2322: Type 'string' is not assignable to type 'T'.
|
|
'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
|
|
derivedGenericClassWithAny.ts(41,1): error TS2322: Type 'E<string>' is not assignable to type 'C<number>'.
|
|
Types of property 'x' are incompatible.
|
|
Type 'string' is not assignable to type 'number'.
|
|
|
|
|
|
==== derivedGenericClassWithAny.ts (7 errors) ====
|
|
class C<T extends number> {
|
|
x: T;
|
|
~
|
|
!!! error TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor.
|
|
get X(): T { return null; }
|
|
~~~~~~
|
|
!!! error TS2322: Type 'null' is not assignable to type 'T'.
|
|
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'null'.
|
|
foo(): T {
|
|
return null;
|
|
~~~~~~
|
|
!!! error TS2322: Type 'null' is not assignable to type 'T'.
|
|
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'null'.
|
|
}
|
|
}
|
|
|
|
class D extends C<number> {
|
|
x: any;
|
|
get X(): any {
|
|
return null;
|
|
}
|
|
foo(): any {
|
|
return 1;
|
|
}
|
|
|
|
static y: any;
|
|
static get Y(): any {
|
|
return null;
|
|
}
|
|
static bar(): any {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// if D is a valid class definition than E is now not safe tranisitively through C
|
|
class E<T extends string> extends D {
|
|
x: T;
|
|
~
|
|
!!! error TS2564: Property 'x' has no initializer and is not definitely assigned in the constructor.
|
|
get X(): T { return ''; } // error
|
|
~~~~~~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'T'.
|
|
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
|
|
foo(): T {
|
|
return ''; // error
|
|
~~~~~~
|
|
!!! error TS2322: Type 'string' is not assignable to type 'T'.
|
|
!!! error TS2322: 'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
|
|
}
|
|
}
|
|
|
|
declare var c: C<number>;
|
|
declare var d: D;
|
|
declare var e: E<string>;
|
|
|
|
c = d;
|
|
c = e;
|
|
~
|
|
!!! error TS2322: Type 'E<string>' is not assignable to type 'C<number>'.
|
|
!!! error TS2322: Types of property 'x' are incompatible.
|
|
!!! error TS2322: Type 'string' is not assignable to type 'number'.
|
|
var r = c.foo(); // e.foo would return string |