Files
tsgo/testdata/baselines/reference/submodule/compiler/genericSpecializations3.errors.txt

83 lines
4.0 KiB
Plaintext

genericSpecializations3.ts(9,5): error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
Type '(x: string) => string' is not assignable to type '(x: number) => number'.
Types of parameters 'x' and 'x' are incompatible.
Type 'number' is not assignable to type 'string'.
genericSpecializations3.ts(9,30): error TS2322: Type 'null' is not assignable to type 'string'.
genericSpecializations3.ts(15,30): error TS2322: Type 'null' is not assignable to type 'number'.
genericSpecializations3.ts(21,30): error TS2322: Type 'null' is not assignable to type 'string'.
genericSpecializations3.ts(28,1): error TS2322: Type 'StringFoo2' is not assignable to type 'IntFoo'.
Types of property 'foo' are incompatible.
Type '(x: string) => string' is not assignable to type '(x: number) => number'.
Types of parameters 'x' and 'x' are incompatible.
Type 'number' is not assignable to type 'string'.
genericSpecializations3.ts(29,1): error TS2322: Type 'IntFoo' is not assignable to type 'StringFoo2'.
Types of property 'foo' are incompatible.
Type '(x: number) => number' is not assignable to type '(x: string) => string'.
Types of parameters 'x' and 'x' are incompatible.
Type 'string' is not assignable to type 'number'.
genericSpecializations3.ts(33,23): error TS2322: Type 'null' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'null'.
==== genericSpecializations3.ts (7 errors) ====
interface IFoo<T> {
foo(x: T): T;
}
declare var iFoo: IFoo<number>;
iFoo.foo(1);
class IntFooBad implements IFoo<number> { // error
foo(x: string): string { return null; }
~~~
!!! error TS2416: Property 'foo' in type 'IntFooBad' is not assignable to the same property in base type 'IFoo<number>'.
!!! error TS2416: Type '(x: string) => string' is not assignable to type '(x: number) => number'.
!!! error TS2416: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2416: Type 'number' is not assignable to type 'string'.
~~~~~~
!!! error TS2322: Type 'null' is not assignable to type 'string'.
}
declare var intFooBad: IntFooBad;
class IntFoo implements IFoo<number> {
foo(x: number): number { return null; }
~~~~~~
!!! error TS2322: Type 'null' is not assignable to type 'number'.
}
declare var intFoo: IntFoo;
class StringFoo2 implements IFoo<string> {
foo(x: string): string { return null; }
~~~~~~
!!! error TS2322: Type 'null' is not assignable to type 'string'.
}
declare var stringFoo2: StringFoo2;
stringFoo2.foo("hm");
intFoo = stringFoo2; // error
~~~~~~
!!! error TS2322: Type 'StringFoo2' is not assignable to type 'IntFoo'.
!!! error TS2322: Types of property 'foo' are incompatible.
!!! error TS2322: Type '(x: string) => string' is not assignable to type '(x: number) => number'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
stringFoo2 = intFoo; // error
~~~~~~~~~~
!!! error TS2322: Type 'IntFoo' is not assignable to type 'StringFoo2'.
!!! error TS2322: Types of property 'foo' are incompatible.
!!! error TS2322: Type '(x: number) => number' is not assignable to type '(x: string) => string'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'string' is not assignable to type 'number'.
class StringFoo3 implements IFoo<string> { // error
foo<T>(x: T): 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'.
}
var stringFoo3: StringFoo3;