2014-08-15 23:33:16 +02:00
|
|
|
=== tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithGenericConstructSignaturesDifferingByReturnType.ts ===
|
|
|
|
// Two call or construct signatures are considered identical when they have the same number of type parameters and, considering those
|
|
|
|
// parameters pairwise identical, have identical type parameter constraints, identical number of parameters with identical kind(required,
|
|
|
|
// optional or rest) and types, and identical return types.
|
|
|
|
|
|
|
|
class B<T> {
|
|
|
|
>B : B<T>
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
constructor(x: T) { return null; }
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
class C<T> {
|
|
|
|
>C : C<T>
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
constructor(x: T) { return null; }
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
}
|
|
|
|
|
|
|
|
interface I<T> {
|
|
|
|
>I : I<T>
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
new(x: T): Date;
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
>Date : Date
|
|
|
|
}
|
|
|
|
|
|
|
|
interface I2 {
|
|
|
|
>I2 : I2
|
|
|
|
|
|
|
|
new<T>(x: T): RegExp;
|
|
|
|
>T : T
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
>RegExp : RegExp
|
|
|
|
}
|
|
|
|
|
|
|
|
var a: { new<T>(x: T): T }
|
|
|
|
>a : new <T>(x: T) => T
|
|
|
|
>T : T
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
var b = { new<T>(x: T): T { return null; } }; // not a construct signature, function called new
|
2014-12-03 12:05:37 +01:00
|
|
|
>b : { new<T>(x: T): T; }
|
|
|
|
>{ new<T>(x: T): T { return null; } } : { new<T>(x: T): T; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>new : <T>(x: T) => T
|
|
|
|
>T : T
|
|
|
|
>x : T
|
|
|
|
>T : T
|
|
|
|
>T : T
|
|
|
|
|
|
|
|
function foo1b(x: B<string>);
|
|
|
|
>foo1b : { (x: B<string>): any; (x: B<string>): any; }
|
|
|
|
>x : B<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>B : B<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo1b(x: B<string>); // error
|
|
|
|
>foo1b : { (x: B<string>): any; (x: B<string>): any; }
|
|
|
|
>x : B<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>B : B<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo1b(x: any) { }
|
|
|
|
>foo1b : { (x: B<string>): any; (x: B<string>): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo1c(x: C<string>);
|
|
|
|
>foo1c : { (x: C<string>): any; (x: C<string>): any; }
|
|
|
|
>x : C<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>C : C<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo1c(x: C<string>); // error
|
|
|
|
>foo1c : { (x: C<string>): any; (x: C<string>): any; }
|
|
|
|
>x : C<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>C : C<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo1c(x: any) { }
|
|
|
|
>foo1c : { (x: C<string>): any; (x: C<string>): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo2(x: I<string>);
|
|
|
|
>foo2 : { (x: I<string>): any; (x: I<string>): any; }
|
|
|
|
>x : I<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo2(x: I<string>); // error
|
|
|
|
>foo2 : { (x: I<string>): any; (x: I<string>): any; }
|
|
|
|
>x : I<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo2(x: any) { }
|
|
|
|
>foo2 : { (x: I<string>): any; (x: I<string>): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo3(x: typeof a);
|
|
|
|
>foo3 : { (x: new <T>(x: T) => T): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : new <T>(x: T) => T
|
|
|
|
>a : new <T>(x: T) => T
|
|
|
|
|
|
|
|
function foo3(x: typeof a); // error
|
|
|
|
>foo3 : { (x: new <T>(x: T) => T): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : new <T>(x: T) => T
|
|
|
|
>a : new <T>(x: T) => T
|
|
|
|
|
|
|
|
function foo3(x: any) { }
|
|
|
|
>foo3 : { (x: new <T>(x: T) => T): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo4(x: typeof b);
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo4 : { (x: { new<T>(x: T): T; }): any; (x: { new<T>(x: T): T; }): any; }
|
|
|
|
>x : { new<T>(x: T): T; }
|
|
|
|
>b : { new<T>(x: T): T; }
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo4(x: typeof b); // error
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo4 : { (x: { new<T>(x: T): T; }): any; (x: { new<T>(x: T): T; }): any; }
|
|
|
|
>x : { new<T>(x: T): T; }
|
|
|
|
>b : { new<T>(x: T): T; }
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo4(x: any) { }
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo4 : { (x: { new<T>(x: T): T; }): any; (x: { new<T>(x: T): T; }): any; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo5(x: typeof a): number;
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo5 : { (x: new <T>(x: T) => T): number; (x: { new<T>(x: T): T; }): string; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : new <T>(x: T) => T
|
|
|
|
>a : new <T>(x: T) => T
|
|
|
|
|
|
|
|
function foo5(x: typeof b): string; // ok
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo5 : { (x: new <T>(x: T) => T): number; (x: { new<T>(x: T): T; }): string; }
|
|
|
|
>x : { new<T>(x: T): T; }
|
|
|
|
>b : { new<T>(x: T): T; }
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo5(x: any): any { }
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo5 : { (x: new <T>(x: T) => T): number; (x: { new<T>(x: T): T; }): string; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo8(x: B<string>);
|
|
|
|
>foo8 : { (x: B<string>): any; (x: I<string>): any; }
|
|
|
|
>x : B<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>B : B<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo8(x: I<string>); // ok
|
|
|
|
>foo8 : { (x: B<string>): any; (x: I<string>): any; }
|
|
|
|
>x : I<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo8(x: any) { }
|
|
|
|
>foo8 : { (x: B<string>): any; (x: I<string>): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo9(x: B<string>);
|
|
|
|
>foo9 : { (x: B<string>): any; (x: C<string>): any; }
|
|
|
|
>x : B<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>B : B<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo9(x: C<string>); // error since types are structurally equal
|
|
|
|
>foo9 : { (x: B<string>): any; (x: C<string>): any; }
|
|
|
|
>x : C<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>C : C<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo9(x: any) { }
|
|
|
|
>foo9 : { (x: B<string>): any; (x: C<string>): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo10(x: B<string>);
|
|
|
|
>foo10 : { (x: B<string>): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : B<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>B : B<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo10(x: typeof a); // ok
|
|
|
|
>foo10 : { (x: B<string>): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : new <T>(x: T) => T
|
|
|
|
>a : new <T>(x: T) => T
|
|
|
|
|
|
|
|
function foo10(x: any) { }
|
|
|
|
>foo10 : { (x: B<string>): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo11(x: B<string>);
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo11 : { (x: B<string>): any; (x: { new<T>(x: T): T; }): any; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : B<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>B : B<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo11(x: typeof b); // ok
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo11 : { (x: B<string>): any; (x: { new<T>(x: T): T; }): any; }
|
|
|
|
>x : { new<T>(x: T): T; }
|
|
|
|
>b : { new<T>(x: T): T; }
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo11(x: any) { }
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo11 : { (x: B<string>): any; (x: { new<T>(x: T): T; }): any; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo12(x: I<string>);
|
|
|
|
>foo12 : { (x: I<string>): any; (x: C<string>): any; }
|
|
|
|
>x : I<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo12(x: C<string>); // ok
|
|
|
|
>foo12 : { (x: I<string>): any; (x: C<string>): any; }
|
|
|
|
>x : C<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>C : C<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo12(x: any) { }
|
|
|
|
>foo12 : { (x: I<string>): any; (x: C<string>): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo12b(x: I2);
|
|
|
|
>foo12b : { (x: I2): any; (x: C<string>): any; }
|
|
|
|
>x : I2
|
|
|
|
>I2 : I2
|
|
|
|
|
|
|
|
function foo12b(x: C<string>); // ok
|
|
|
|
>foo12b : { (x: I2): any; (x: C<string>): any; }
|
|
|
|
>x : C<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>C : C<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo12b(x: any) { }
|
|
|
|
>foo12b : { (x: I2): any; (x: C<string>): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo13(x: I<string>);
|
|
|
|
>foo13 : { (x: I<string>): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : I<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo13(x: typeof a); // ok
|
|
|
|
>foo13 : { (x: I<string>): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : new <T>(x: T) => T
|
|
|
|
>a : new <T>(x: T) => T
|
|
|
|
|
|
|
|
function foo13(x: any) { }
|
|
|
|
>foo13 : { (x: I<string>): any; (x: new <T>(x: T) => T): any; }
|
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo14(x: I<string>);
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo14 : { (x: I<string>): any; (x: { new<T>(x: T): T; }): any; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : I<string>
|
2014-08-19 04:56:03 +02:00
|
|
|
>I : I<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo14(x: typeof b); // ok
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo14 : { (x: I<string>): any; (x: { new<T>(x: T): T; }): any; }
|
|
|
|
>x : { new<T>(x: T): T; }
|
|
|
|
>b : { new<T>(x: T): T; }
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo14(x: any) { }
|
2014-12-03 12:05:37 +01:00
|
|
|
>foo14 : { (x: I<string>): any; (x: { new<T>(x: T): T; }): any; }
|
2014-08-15 23:33:16 +02:00
|
|
|
>x : any
|
|
|
|
|
|
|
|
function foo15(x: I2);
|
|
|
|
>foo15 : { (x: I2): any; (x: C<number>): any; }
|
|
|
|
>x : I2
|
|
|
|
>I2 : I2
|
|
|
|
|
|
|
|
function foo15(x: C<number>); // ok
|
|
|
|
>foo15 : { (x: I2): any; (x: C<number>): any; }
|
|
|
|
>x : C<number>
|
2014-08-19 04:56:03 +02:00
|
|
|
>C : C<T>
|
2014-08-15 23:33:16 +02:00
|
|
|
|
|
|
|
function foo15(x: any) { }
|
|
|
|
>foo15 : { (x: I2): any; (x: C<number>): any; }
|
|
|
|
>x : any
|
|
|
|
|