From 4384c906706e55aec03fe99a7d380549c2940020 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 25 Apr 2019 09:58:39 -0700 Subject: [PATCH 1/8] Support higher order inferences for constructor functions --- src/compiler/checker.ts | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ce56db4b962f4..bad5e88c0f70e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8563,7 +8563,9 @@ namespace ts { function getSignatureInstantiation(signature: Signature, typeArguments: Type[] | undefined, isJavascript: boolean, inferredTypeParameters?: ReadonlyArray): Signature { const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript)); if (inferredTypeParameters) { - const returnSignature = getSingleCallSignature(getReturnTypeOfSignature(instantiatedSignature)); + const returnType = getReturnTypeOfSignature(instantiatedSignature); + const returnSignature = getSingleSignature(returnType, SignatureKind.Call, /*allowMembers*/ false) || + getSingleSignature(returnType, SignatureKind.Construct, /*allowMembers*/ false); if (returnSignature) { const newReturnSignature = cloneSignature(returnSignature); newReturnSignature.typeParameters = inferredTypeParameters; @@ -8639,7 +8641,8 @@ namespace ts { // object type literal or interface (using the new keyword). Each way of declaring a constructor // will result in a different declaration kind. if (!signature.isolatedSignatureType) { - const isConstructor = signature.declaration!.kind === SyntaxKind.Constructor || signature.declaration!.kind === SyntaxKind.ConstructSignature; // TODO: GH#18217 + const kind = signature.declaration ? signature.declaration.kind : SyntaxKind.Unknown; + const isConstructor = kind === SyntaxKind.Constructor || kind === SyntaxKind.ConstructSignature || kind === SyntaxKind.ConstructorType; const type = createObjectType(ObjectFlags.Anonymous); type.members = emptySymbols; type.properties = emptyArray; @@ -20421,11 +20424,19 @@ namespace ts { // If type has a single call signature and no other members, return that signature. Otherwise, return undefined. function getSingleCallSignature(type: Type): Signature | undefined { + return getSingleSignature(type, SignatureKind.Call, /*allowMembers*/ false); + } + + function getSingleSignature(type: Type, kind: SignatureKind, allowMembers: boolean): Signature | undefined { if (type.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(type); - if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && - resolved.properties.length === 0 && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { - return resolved.callSignatures[0]; + if (allowMembers || resolved.properties.length === 0 && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { + if (kind === SignatureKind.Call && resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0) { + return resolved.callSignatures[0]; + } + if (kind === SignatureKind.Construct && resolved.constructSignatures.length === 1 && resolved.callSignatures.length === 0) { + return resolved.constructSignatures[0]; + } } } return undefined; @@ -23760,15 +23771,17 @@ namespace ts { function instantiateTypeWithSingleGenericCallSignature(node: Expression | MethodDeclaration | QualifiedName, type: Type, checkMode?: CheckMode) { if (checkMode && checkMode & (CheckMode.Inferential | CheckMode.SkipGenericFunctions)) { - const signature = getSingleCallSignature(type); + const callSignature = getSingleSignature(type, SignatureKind.Call, /*allowMembers*/ true); + const constructSignature = getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ true); + const signature = callSignature || constructSignature; if (signature && signature.typeParameters) { if (checkMode & CheckMode.SkipGenericFunctions) { skippedGenericFunction(node, checkMode); return anyFunctionType; } const contextualType = getApparentTypeOfContextualType(node); - if (contextualType) { - const contextualSignature = getSingleCallSignature(getNonNullableType(contextualType)); + if (contextualType && !isMixinConstructorType(contextualType)) { + const contextualSignature = getSingleSignature(getNonNullableType(contextualType), callSignature ? SignatureKind.Call : SignatureKind.Construct, /*allowMembers*/ false); if (contextualSignature && !contextualSignature.typeParameters) { const context = getInferenceContext(node)!; // We have an expression that is an argument of a generic function for which we are performing @@ -23777,7 +23790,10 @@ namespace ts { // if the outer function returns a function type with a single non-generic call signature and // if some of the outer function type parameters have no inferences so far. If so, we can // potentially add inferred type parameters to the outer function return type. - const returnSignature = context.signature && getSingleCallSignature(getReturnTypeOfSignature(context.signature)); + const returnType = context.signature && getReturnTypeOfSignature(context.signature); + const returnSignature = returnType && ( + getSingleSignature(returnType, SignatureKind.Call, /*allowMembers*/ false) || + getSingleSignature(returnType, SignatureKind.Construct, /*allowMembers*/ false)); if (returnSignature && !returnSignature.typeParameters && !every(context.inferences, hasInferenceCandidates)) { // Instantiate the signature with its own type parameters as type arguments, possibly // renaming the type parameters to ensure they have unique names. From fcd6f5225acda3254a4e53ed12ad854bbeb2e4d1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 25 Apr 2019 10:01:40 -0700 Subject: [PATCH 2/8] Accept new baselines --- .../baselines/reference/bluebirdStaticThis.types | 12 ++++++------ .../genericCallWithFunctionTypedArguments2.types | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/baselines/reference/bluebirdStaticThis.types b/tests/baselines/reference/bluebirdStaticThis.types index 7708a733c5966..eec02478b2bf3 100644 --- a/tests/baselines/reference/bluebirdStaticThis.types +++ b/tests/baselines/reference/bluebirdStaticThis.types @@ -699,9 +699,9 @@ var fooProm: Promise; >fooProm : Promise fooProm = Promise.try(Promise, () => { ->fooProm = Promise.try(Promise, () => { return foo;}) : Promise +>fooProm = Promise.try(Promise, () => { return foo;}) : any >fooProm : Promise ->Promise.try(Promise, () => { return foo;}) : Promise +>Promise.try(Promise, () => { return foo;}) : any >Promise.try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } >Promise : typeof Promise >try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } @@ -713,9 +713,9 @@ fooProm = Promise.try(Promise, () => { }); fooProm = Promise.try(Promise, () => { ->fooProm = Promise.try(Promise, () => { return foo;}, arr) : Promise +>fooProm = Promise.try(Promise, () => { return foo;}, arr) : any >fooProm : Promise ->Promise.try(Promise, () => { return foo;}, arr) : Promise +>Promise.try(Promise, () => { return foo;}, arr) : any >Promise.try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } >Promise : typeof Promise >try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } @@ -729,9 +729,9 @@ fooProm = Promise.try(Promise, () => { >arr : any[] fooProm = Promise.try(Promise, () => { ->fooProm = Promise.try(Promise, () => { return foo;}, arr, x) : Promise +>fooProm = Promise.try(Promise, () => { return foo;}, arr, x) : any >fooProm : Promise ->Promise.try(Promise, () => { return foo;}, arr, x) : Promise +>Promise.try(Promise, () => { return foo;}, arr, x) : any >Promise.try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } >Promise : typeof Promise >try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } diff --git a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types index 1cd9e7ccd111f..9699261a641fb 100644 --- a/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types +++ b/tests/baselines/reference/genericCallWithFunctionTypedArguments2.types @@ -78,15 +78,15 @@ var r4 = foo2(1, i2); // error >i2 : I2 var r4b = foo2(1, a); // any ->r4b : unknown ->foo2(1, a) : unknown +>r4b : number +>foo2(1, a) : number >foo2 : (x: T, cb: new (a: T) => U) => U >1 : 1 >a : new (x: T) => T var r5 = foo2(1, i); // any ->r5 : unknown ->foo2(1, i) : unknown +>r5 : number +>foo2(1, i) : number >foo2 : (x: T, cb: new (a: T) => U) => U >1 : 1 >i : I @@ -112,16 +112,16 @@ function foo3(x: T, cb: new(a: T) => U, y: U) { } var r7 = foo3(null, i, ''); // any ->r7 : unknown ->foo3(null, i, '') : unknown +>r7 : any +>foo3(null, i, '') : any >foo3 : (x: T, cb: new (a: T) => U, y: U) => U >null : null >i : I >'' : "" var r7b = foo3(null, a, ''); // any ->r7b : unknown ->foo3(null, a, '') : unknown +>r7b : any +>foo3(null, a, '') : any >foo3 : (x: T, cb: new (a: T) => U, y: U) => U >null : null >a : new (x: T) => T From 4fe59dc705bfa2975df365b9fa6a9dd58f9ce2b4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 25 Apr 2019 13:02:02 -0700 Subject: [PATCH 3/8] Only defer pure functions and pure constructor functions during inference --- src/compiler/checker.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bad5e88c0f70e..5a414c488f286 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8563,9 +8563,7 @@ namespace ts { function getSignatureInstantiation(signature: Signature, typeArguments: Type[] | undefined, isJavascript: boolean, inferredTypeParameters?: ReadonlyArray): Signature { const instantiatedSignature = getSignatureInstantiationWithoutFillingInTypeArguments(signature, fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript)); if (inferredTypeParameters) { - const returnType = getReturnTypeOfSignature(instantiatedSignature); - const returnSignature = getSingleSignature(returnType, SignatureKind.Call, /*allowMembers*/ false) || - getSingleSignature(returnType, SignatureKind.Construct, /*allowMembers*/ false); + const returnSignature = getSingleCallOrConstructSignature(getReturnTypeOfSignature(instantiatedSignature)); if (returnSignature) { const newReturnSignature = cloneSignature(returnSignature); newReturnSignature.typeParameters = inferredTypeParameters; @@ -20427,6 +20425,11 @@ namespace ts { return getSingleSignature(type, SignatureKind.Call, /*allowMembers*/ false); } + function getSingleCallOrConstructSignature(type: Type): Signature | undefined { + return getSingleSignature(type, SignatureKind.Call, /*allowMembers*/ false) || + getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ false); + } + function getSingleSignature(type: Type, kind: SignatureKind, allowMembers: boolean): Signature | undefined { if (type.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(type); @@ -23775,7 +23778,7 @@ namespace ts { const constructSignature = getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ true); const signature = callSignature || constructSignature; if (signature && signature.typeParameters) { - if (checkMode & CheckMode.SkipGenericFunctions) { + if (checkMode & CheckMode.SkipGenericFunctions && getSingleCallOrConstructSignature(type)) { skippedGenericFunction(node, checkMode); return anyFunctionType; } @@ -23791,9 +23794,7 @@ namespace ts { // if some of the outer function type parameters have no inferences so far. If so, we can // potentially add inferred type parameters to the outer function return type. const returnType = context.signature && getReturnTypeOfSignature(context.signature); - const returnSignature = returnType && ( - getSingleSignature(returnType, SignatureKind.Call, /*allowMembers*/ false) || - getSingleSignature(returnType, SignatureKind.Construct, /*allowMembers*/ false)); + const returnSignature = returnType && getSingleCallOrConstructSignature(returnType); if (returnSignature && !returnSignature.typeParameters && !every(context.inferences, hasInferenceCandidates)) { // Instantiate the signature with its own type parameters as type arguments, possibly // renaming the type parameters to ensure they have unique names. From 50f5e160aa3b52881eeb481a6601dc9c266bb50d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 25 Apr 2019 13:46:45 -0700 Subject: [PATCH 4/8] Accept new baselines --- tests/baselines/reference/bluebirdStaticThis.types | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/bluebirdStaticThis.types b/tests/baselines/reference/bluebirdStaticThis.types index eec02478b2bf3..7708a733c5966 100644 --- a/tests/baselines/reference/bluebirdStaticThis.types +++ b/tests/baselines/reference/bluebirdStaticThis.types @@ -699,9 +699,9 @@ var fooProm: Promise; >fooProm : Promise fooProm = Promise.try(Promise, () => { ->fooProm = Promise.try(Promise, () => { return foo;}) : any +>fooProm = Promise.try(Promise, () => { return foo;}) : Promise >fooProm : Promise ->Promise.try(Promise, () => { return foo;}) : any +>Promise.try(Promise, () => { return foo;}) : Promise >Promise.try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } >Promise : typeof Promise >try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } @@ -713,9 +713,9 @@ fooProm = Promise.try(Promise, () => { }); fooProm = Promise.try(Promise, () => { ->fooProm = Promise.try(Promise, () => { return foo;}, arr) : any +>fooProm = Promise.try(Promise, () => { return foo;}, arr) : Promise >fooProm : Promise ->Promise.try(Promise, () => { return foo;}, arr) : any +>Promise.try(Promise, () => { return foo;}, arr) : Promise >Promise.try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } >Promise : typeof Promise >try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } @@ -729,9 +729,9 @@ fooProm = Promise.try(Promise, () => { >arr : any[] fooProm = Promise.try(Promise, () => { ->fooProm = Promise.try(Promise, () => { return foo;}, arr, x) : any +>fooProm = Promise.try(Promise, () => { return foo;}, arr, x) : Promise >fooProm : Promise ->Promise.try(Promise, () => { return foo;}, arr, x) : any +>Promise.try(Promise, () => { return foo;}, arr, x) : Promise >Promise.try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } >Promise : typeof Promise >try : { (dit: typeof Promise, fn: () => Promise.Thenable, args?: any[], ctx?: any): Promise; (dit: typeof Promise, fn: () => R, args?: any[], ctx?: any): Promise; } From be88d53ab37453585b449b6ab1918134087b03cf Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 25 Apr 2019 17:32:27 -0700 Subject: [PATCH 5/8] Only defer function type inference when contextual type is function type --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5a414c488f286..86d80b8438a9e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23778,14 +23778,14 @@ namespace ts { const constructSignature = getSingleSignature(type, SignatureKind.Construct, /*allowMembers*/ true); const signature = callSignature || constructSignature; if (signature && signature.typeParameters) { - if (checkMode & CheckMode.SkipGenericFunctions && getSingleCallOrConstructSignature(type)) { - skippedGenericFunction(node, checkMode); - return anyFunctionType; - } const contextualType = getApparentTypeOfContextualType(node); if (contextualType && !isMixinConstructorType(contextualType)) { const contextualSignature = getSingleSignature(getNonNullableType(contextualType), callSignature ? SignatureKind.Call : SignatureKind.Construct, /*allowMembers*/ false); if (contextualSignature && !contextualSignature.typeParameters) { + if (checkMode & CheckMode.SkipGenericFunctions) { + skippedGenericFunction(node, checkMode); + return anyFunctionType; + } const context = getInferenceContext(node)!; // We have an expression that is an argument of a generic function for which we are performing // type argument inference. The expression is of a function type with a single generic call From 3e79e8d18dee328b2cc57b8d7a094b42f66b969e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 25 Apr 2019 17:33:01 -0700 Subject: [PATCH 6/8] Accept new baselines --- tests/baselines/reference/genericFunctionInference1.types | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/baselines/reference/genericFunctionInference1.types b/tests/baselines/reference/genericFunctionInference1.types index 5df3fa398c51c..a78d20c133957 100644 --- a/tests/baselines/reference/genericFunctionInference1.types +++ b/tests/baselines/reference/genericFunctionInference1.types @@ -835,7 +835,7 @@ foo2(() => {}); >() => {} : () => void foo2(identity); ->foo2(identity) : [(value: T) => T, unknown] +>foo2(identity) : [(value: T) => T, (value: T) => T] >foo2 : (fn: T, a?: U | undefined, b?: U | undefined) => [T, U] >identity : (value: T) => T From 53cbea78465c642215f6f431977c057a68cea9d5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 27 Apr 2019 07:51:05 -0700 Subject: [PATCH 7/8] Add tests --- .../compiler/genericFunctionInference1.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/cases/compiler/genericFunctionInference1.ts b/tests/cases/compiler/genericFunctionInference1.ts index c6b864f82e518..c90c94cf5e874 100644 --- a/tests/cases/compiler/genericFunctionInference1.ts +++ b/tests/cases/compiler/genericFunctionInference1.ts @@ -65,6 +65,53 @@ declare function baz(t1: T, t2: T, u: U): [T, U]; let f60 = wrap3(baz); +declare const list2: { + (a: T): T[]; + foo: string; + bar(): number; +} + +let f70 = pipe(list2, box); +let f71 = pipe(box, list2); + +declare class Point { + constructor(x: number, y: number); + readonly x: number; + readonly y: number; +} + +declare class Bag { + constructor(...args: T[]); + contains(value: T): boolean; + static foo: string; +} + +function asFunction(cf: new (...args: A) => B) { + return (...args: A) => new cf(...args); +} + +const newPoint = asFunction(Point); +const newBag = asFunction(Bag); +const p1 = new Point(10, 20); +const p2 = newPoint(10, 20); +const bag1 = new Bag(1, 2, 3); +const bag2 = newBag('a', 'b', 'c'); + +declare class Comp

{ + props: P; + constructor(props: P); +} + +type CompClass

= new (props: P) => Comp

; + +declare function myHoc

(C: CompClass

): CompClass

; + +type GenericProps = { foo: number, stuff: T }; + +declare class GenericComp extends Comp> {} + +const GenericComp2 = myHoc(GenericComp); + // #417 function mirror(f: (a: A) => B): (a: A) => B { return f; } From 4051d73cb0b5dfbbfa04275fd8931515d0afbfc8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 27 Apr 2019 07:51:12 -0700 Subject: [PATCH 8/8] Accept new baselines --- .../genericFunctionInference1.errors.txt | 49 +- .../reference/genericFunctionInference1.js | 59 ++ .../genericFunctionInference1.symbols | 614 +++++++++++------- .../reference/genericFunctionInference1.types | 144 ++++ 4 files changed, 633 insertions(+), 233 deletions(-) diff --git a/tests/baselines/reference/genericFunctionInference1.errors.txt b/tests/baselines/reference/genericFunctionInference1.errors.txt index 7fcbc93ea0dca..5c910e7ff5d26 100644 --- a/tests/baselines/reference/genericFunctionInference1.errors.txt +++ b/tests/baselines/reference/genericFunctionInference1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/genericFunctionInference1.ts(88,14): error TS2345: Argument of type '(value: { key: a; }) => a' is not assignable to parameter of type '(value: Data) => string'. +tests/cases/compiler/genericFunctionInference1.ts(135,14): error TS2345: Argument of type '(value: { key: a; }) => a' is not assignable to parameter of type '(value: Data) => string'. Type 'number' is not assignable to type 'string'. @@ -67,6 +67,53 @@ tests/cases/compiler/genericFunctionInference1.ts(88,14): error TS2345: Argument let f60 = wrap3(baz); + declare const list2: { + (a: T): T[]; + foo: string; + bar(): number; + } + + let f70 = pipe(list2, box); + let f71 = pipe(box, list2); + + declare class Point { + constructor(x: number, y: number); + readonly x: number; + readonly y: number; + } + + declare class Bag { + constructor(...args: T[]); + contains(value: T): boolean; + static foo: string; + } + + function asFunction(cf: new (...args: A) => B) { + return (...args: A) => new cf(...args); + } + + const newPoint = asFunction(Point); + const newBag = asFunction(Bag); + const p1 = new Point(10, 20); + const p2 = newPoint(10, 20); + const bag1 = new Bag(1, 2, 3); + const bag2 = newBag('a', 'b', 'c'); + + declare class Comp

{ + props: P; + constructor(props: P); + } + + type CompClass

= new (props: P) => Comp

; + + declare function myHoc

(C: CompClass

): CompClass

; + + type GenericProps = { foo: number, stuff: T }; + + declare class GenericComp extends Comp> {} + + const GenericComp2 = myHoc(GenericComp); + // #417 function mirror(f: (a: A) => B): (a: A) => B { return f; } diff --git a/tests/baselines/reference/genericFunctionInference1.js b/tests/baselines/reference/genericFunctionInference1.js index 7180fca9033ac..c4a23217023fc 100644 --- a/tests/baselines/reference/genericFunctionInference1.js +++ b/tests/baselines/reference/genericFunctionInference1.js @@ -63,6 +63,53 @@ declare function baz(t1: T, t2: T, u: U): [T, U]; let f60 = wrap3(baz); +declare const list2: { + (a: T): T[]; + foo: string; + bar(): number; +} + +let f70 = pipe(list2, box); +let f71 = pipe(box, list2); + +declare class Point { + constructor(x: number, y: number); + readonly x: number; + readonly y: number; +} + +declare class Bag { + constructor(...args: T[]); + contains(value: T): boolean; + static foo: string; +} + +function asFunction(cf: new (...args: A) => B) { + return (...args: A) => new cf(...args); +} + +const newPoint = asFunction(Point); +const newBag = asFunction(Bag); +const p1 = new Point(10, 20); +const p2 = newPoint(10, 20); +const bag1 = new Bag(1, 2, 3); +const bag2 = newBag('a', 'b', 'c'); + +declare class Comp

{ + props: P; + constructor(props: P); +} + +type CompClass

= new (props: P) => Comp

; + +declare function myHoc

(C: CompClass

): CompClass

; + +type GenericProps = { foo: number, stuff: T }; + +declare class GenericComp extends Comp> {} + +const GenericComp2 = myHoc(GenericComp); + // #417 function mirror(f: (a: A) => B): (a: A) => B { return f; } @@ -242,6 +289,18 @@ const f40 = pipe4([list, box]); const f41 = pipe4([box, list]); const f50 = pipe5(list); // No higher order inference let f60 = wrap3(baz); +let f70 = pipe(list2, box); +let f71 = pipe(box, list2); +function asFunction(cf) { + return (...args) => new cf(...args); +} +const newPoint = asFunction(Point); +const newBag = asFunction(Bag); +const p1 = new Point(10, 20); +const p2 = newPoint(10, 20); +const bag1 = new Bag(1, 2, 3); +const bag2 = newBag('a', 'b', 'c'); +const GenericComp2 = myHoc(GenericComp); // #417 function mirror(f) { return f; } var identityM = mirror(identity); diff --git a/tests/baselines/reference/genericFunctionInference1.symbols b/tests/baselines/reference/genericFunctionInference1.symbols index 9d6005de9cf31..0c2881bb1ce62 100644 --- a/tests/baselines/reference/genericFunctionInference1.symbols +++ b/tests/baselines/reference/genericFunctionInference1.symbols @@ -497,299 +497,449 @@ let f60 = wrap3(baz); >wrap3 : Symbol(wrap3, Decl(genericFunctionInference1.ts, 57, 24)) >baz : Symbol(baz, Decl(genericFunctionInference1.ts, 59, 89)) +declare const list2: { +>list2 : Symbol(list2, Decl(genericFunctionInference1.ts, 64, 13)) + + (a: T): T[]; +>T : Symbol(T, Decl(genericFunctionInference1.ts, 65, 5)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 65, 8)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 65, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 65, 5)) + + foo: string; +>foo : Symbol(foo, Decl(genericFunctionInference1.ts, 65, 19)) + + bar(): number; +>bar : Symbol(bar, Decl(genericFunctionInference1.ts, 66, 16)) +} + +let f70 = pipe(list2, box); +>f70 : Symbol(f70, Decl(genericFunctionInference1.ts, 70, 3)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>list2 : Symbol(list2, Decl(genericFunctionInference1.ts, 64, 13)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) + +let f71 = pipe(box, list2); +>f71 : Symbol(f71, Decl(genericFunctionInference1.ts, 71, 3)) +>pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) +>box : Symbol(box, Decl(genericFunctionInference1.ts, 4, 36)) +>list2 : Symbol(list2, Decl(genericFunctionInference1.ts, 64, 13)) + +declare class Point { +>Point : Symbol(Point, Decl(genericFunctionInference1.ts, 71, 27)) + + constructor(x: number, y: number); +>x : Symbol(x, Decl(genericFunctionInference1.ts, 74, 16)) +>y : Symbol(y, Decl(genericFunctionInference1.ts, 74, 26)) + + readonly x: number; +>x : Symbol(Point.x, Decl(genericFunctionInference1.ts, 74, 38)) + + readonly y: number; +>y : Symbol(Point.y, Decl(genericFunctionInference1.ts, 75, 23)) +} + +declare class Bag { +>Bag : Symbol(Bag, Decl(genericFunctionInference1.ts, 77, 1)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 79, 18)) + + constructor(...args: T[]); +>args : Symbol(args, Decl(genericFunctionInference1.ts, 80, 16)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 79, 18)) + + contains(value: T): boolean; +>contains : Symbol(Bag.contains, Decl(genericFunctionInference1.ts, 80, 30)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 81, 13)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 79, 18)) + + static foo: string; +>foo : Symbol(Bag.foo, Decl(genericFunctionInference1.ts, 81, 32)) +} + +function asFunction(cf: new (...args: A) => B) { +>asFunction : Symbol(asFunction, Decl(genericFunctionInference1.ts, 83, 1)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 85, 20)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 85, 36)) +>cf : Symbol(cf, Decl(genericFunctionInference1.ts, 85, 40)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 85, 49)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 85, 20)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 85, 36)) + + return (...args: A) => new cf(...args); +>args : Symbol(args, Decl(genericFunctionInference1.ts, 86, 12)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 85, 20)) +>cf : Symbol(cf, Decl(genericFunctionInference1.ts, 85, 40)) +>args : Symbol(args, Decl(genericFunctionInference1.ts, 86, 12)) +} + +const newPoint = asFunction(Point); +>newPoint : Symbol(newPoint, Decl(genericFunctionInference1.ts, 89, 5)) +>asFunction : Symbol(asFunction, Decl(genericFunctionInference1.ts, 83, 1)) +>Point : Symbol(Point, Decl(genericFunctionInference1.ts, 71, 27)) + +const newBag = asFunction(Bag); +>newBag : Symbol(newBag, Decl(genericFunctionInference1.ts, 90, 5)) +>asFunction : Symbol(asFunction, Decl(genericFunctionInference1.ts, 83, 1)) +>Bag : Symbol(Bag, Decl(genericFunctionInference1.ts, 77, 1)) + +const p1 = new Point(10, 20); +>p1 : Symbol(p1, Decl(genericFunctionInference1.ts, 91, 5)) +>Point : Symbol(Point, Decl(genericFunctionInference1.ts, 71, 27)) + +const p2 = newPoint(10, 20); +>p2 : Symbol(p2, Decl(genericFunctionInference1.ts, 92, 5)) +>newPoint : Symbol(newPoint, Decl(genericFunctionInference1.ts, 89, 5)) + +const bag1 = new Bag(1, 2, 3); +>bag1 : Symbol(bag1, Decl(genericFunctionInference1.ts, 93, 5)) +>Bag : Symbol(Bag, Decl(genericFunctionInference1.ts, 77, 1)) + +const bag2 = newBag('a', 'b', 'c'); +>bag2 : Symbol(bag2, Decl(genericFunctionInference1.ts, 94, 5)) +>newBag : Symbol(newBag, Decl(genericFunctionInference1.ts, 90, 5)) + +declare class Comp

{ +>Comp : Symbol(Comp, Decl(genericFunctionInference1.ts, 94, 35)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 96, 19)) + + props: P; +>props : Symbol(Comp.props, Decl(genericFunctionInference1.ts, 96, 23)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 96, 19)) + + constructor(props: P); +>props : Symbol(props, Decl(genericFunctionInference1.ts, 98, 16)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 96, 19)) +} + +type CompClass

= new (props: P) => Comp

; +>CompClass : Symbol(CompClass, Decl(genericFunctionInference1.ts, 99, 1)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 101, 15)) +>props : Symbol(props, Decl(genericFunctionInference1.ts, 101, 25)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 101, 15)) +>Comp : Symbol(Comp, Decl(genericFunctionInference1.ts, 94, 35)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 101, 15)) + +declare function myHoc

(C: CompClass

): CompClass

; +>myHoc : Symbol(myHoc, Decl(genericFunctionInference1.ts, 101, 46)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 103, 23)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 103, 26)) +>CompClass : Symbol(CompClass, Decl(genericFunctionInference1.ts, 99, 1)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 103, 23)) +>CompClass : Symbol(CompClass, Decl(genericFunctionInference1.ts, 99, 1)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 103, 23)) + +type GenericProps = { foo: number, stuff: T }; +>GenericProps : Symbol(GenericProps, Decl(genericFunctionInference1.ts, 103, 57)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 105, 18)) +>foo : Symbol(foo, Decl(genericFunctionInference1.ts, 105, 24)) +>stuff : Symbol(stuff, Decl(genericFunctionInference1.ts, 105, 37)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 105, 18)) + +declare class GenericComp extends Comp> {} +>GenericComp : Symbol(GenericComp, Decl(genericFunctionInference1.ts, 105, 49)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 107, 26)) +>Comp : Symbol(Comp, Decl(genericFunctionInference1.ts, 94, 35)) +>GenericProps : Symbol(GenericProps, Decl(genericFunctionInference1.ts, 103, 57)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 107, 26)) + +const GenericComp2 = myHoc(GenericComp); +>GenericComp2 : Symbol(GenericComp2, Decl(genericFunctionInference1.ts, 109, 5)) +>myHoc : Symbol(myHoc, Decl(genericFunctionInference1.ts, 101, 46)) +>GenericComp : Symbol(GenericComp, Decl(genericFunctionInference1.ts, 105, 49)) + // #417 function mirror(f: (a: A) => B): (a: A) => B { return f; } ->mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 62, 21)) ->A : Symbol(A, Decl(genericFunctionInference1.ts, 66, 16)) ->B : Symbol(B, Decl(genericFunctionInference1.ts, 66, 18)) ->f : Symbol(f, Decl(genericFunctionInference1.ts, 66, 22)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 66, 26)) ->A : Symbol(A, Decl(genericFunctionInference1.ts, 66, 16)) ->B : Symbol(B, Decl(genericFunctionInference1.ts, 66, 18)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 66, 40)) ->A : Symbol(A, Decl(genericFunctionInference1.ts, 66, 16)) ->B : Symbol(B, Decl(genericFunctionInference1.ts, 66, 18)) ->f : Symbol(f, Decl(genericFunctionInference1.ts, 66, 22)) +>mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 109, 40)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 113, 16)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 113, 18)) +>f : Symbol(f, Decl(genericFunctionInference1.ts, 113, 22)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 26)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 113, 16)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 113, 18)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 40)) +>A : Symbol(A, Decl(genericFunctionInference1.ts, 113, 16)) +>B : Symbol(B, Decl(genericFunctionInference1.ts, 113, 18)) +>f : Symbol(f, Decl(genericFunctionInference1.ts, 113, 22)) var identityM = mirror(identity); ->identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 67, 3)) ->mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 62, 21)) ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) +>identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 114, 3)) +>mirror : Symbol(mirror, Decl(genericFunctionInference1.ts, 109, 40)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) var x = 1; ->x : Symbol(x, Decl(genericFunctionInference1.ts, 69, 3)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 116, 3)) var y = identity(x); ->y : Symbol(y, Decl(genericFunctionInference1.ts, 70, 3)) ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 69, 3)) +>y : Symbol(y, Decl(genericFunctionInference1.ts, 117, 3)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 116, 3)) var z = identityM(x); ->z : Symbol(z, Decl(genericFunctionInference1.ts, 71, 3)) ->identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 67, 3)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 69, 3)) +>z : Symbol(z, Decl(genericFunctionInference1.ts, 118, 3)) +>identityM : Symbol(identityM, Decl(genericFunctionInference1.ts, 114, 3)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 116, 3)) // #3038 export function keyOf(value: { key: a; }): a { ->keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 71, 21)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 75, 22)) ->value : Symbol(value, Decl(genericFunctionInference1.ts, 75, 25)) ->key : Symbol(key, Decl(genericFunctionInference1.ts, 75, 33)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 75, 22)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 75, 22)) +>keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 118, 21)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 122, 22)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 122, 25)) +>key : Symbol(key, Decl(genericFunctionInference1.ts, 122, 33)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 122, 22)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 122, 22)) return value.key; ->value.key : Symbol(key, Decl(genericFunctionInference1.ts, 75, 33)) ->value : Symbol(value, Decl(genericFunctionInference1.ts, 75, 25)) ->key : Symbol(key, Decl(genericFunctionInference1.ts, 75, 33)) +>value.key : Symbol(key, Decl(genericFunctionInference1.ts, 122, 33)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 122, 25)) +>key : Symbol(key, Decl(genericFunctionInference1.ts, 122, 33)) } export interface Data { ->Data : Symbol(Data, Decl(genericFunctionInference1.ts, 77, 1)) +>Data : Symbol(Data, Decl(genericFunctionInference1.ts, 124, 1)) key: number; ->key : Symbol(Data.key, Decl(genericFunctionInference1.ts, 78, 23)) +>key : Symbol(Data.key, Decl(genericFunctionInference1.ts, 125, 23)) value: Date; ->value : Symbol(Data.value, Decl(genericFunctionInference1.ts, 79, 16)) +>value : Symbol(Data.value, Decl(genericFunctionInference1.ts, 126, 16)) >Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) } var data: Data[] = []; ->data : Symbol(data, Decl(genericFunctionInference1.ts, 83, 3)) ->Data : Symbol(Data, Decl(genericFunctionInference1.ts, 77, 1)) +>data : Symbol(data, Decl(genericFunctionInference1.ts, 130, 3)) +>Data : Symbol(Data, Decl(genericFunctionInference1.ts, 124, 1)) declare function toKeys(values: a[], toKey: (value: a) => string): string[]; ->toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 83, 22)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 85, 24)) ->values : Symbol(values, Decl(genericFunctionInference1.ts, 85, 27)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 85, 24)) ->toKey : Symbol(toKey, Decl(genericFunctionInference1.ts, 85, 39)) ->value : Symbol(value, Decl(genericFunctionInference1.ts, 85, 48)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 85, 24)) +>toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 130, 22)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 132, 24)) +>values : Symbol(values, Decl(genericFunctionInference1.ts, 132, 27)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 132, 24)) +>toKey : Symbol(toKey, Decl(genericFunctionInference1.ts, 132, 39)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 132, 48)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 132, 24)) toKeys(data, keyOf); // Error ->toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 83, 22)) ->data : Symbol(data, Decl(genericFunctionInference1.ts, 83, 3)) ->keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 71, 21)) +>toKeys : Symbol(toKeys, Decl(genericFunctionInference1.ts, 130, 22)) +>data : Symbol(data, Decl(genericFunctionInference1.ts, 130, 3)) +>keyOf : Symbol(keyOf, Decl(genericFunctionInference1.ts, 118, 21)) // #9366 function flip(f: (a: a, b: b) => c): (b: b, a: a) => c { ->flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16)) ->c : Symbol(c, Decl(genericFunctionInference1.ts, 91, 19)) ->f : Symbol(f, Decl(genericFunctionInference1.ts, 91, 23)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 27)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 32)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16)) ->c : Symbol(c, Decl(genericFunctionInference1.ts, 91, 19)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 47)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 52)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14)) ->c : Symbol(c, Decl(genericFunctionInference1.ts, 91, 19)) +>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 134, 20)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 138, 14)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 138, 16)) +>c : Symbol(c, Decl(genericFunctionInference1.ts, 138, 19)) +>f : Symbol(f, Decl(genericFunctionInference1.ts, 138, 23)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 138, 27)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 138, 14)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 138, 32)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 138, 16)) +>c : Symbol(c, Decl(genericFunctionInference1.ts, 138, 19)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 138, 47)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 138, 16)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 138, 52)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 138, 14)) +>c : Symbol(c, Decl(genericFunctionInference1.ts, 138, 19)) return (b: b, a: a) => f(a, b); ->b : Symbol(b, Decl(genericFunctionInference1.ts, 92, 10)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 91, 16)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 92, 15)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 91, 14)) ->f : Symbol(f, Decl(genericFunctionInference1.ts, 91, 23)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 92, 15)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 92, 10)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 139, 10)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 138, 16)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 139, 15)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 138, 14)) +>f : Symbol(f, Decl(genericFunctionInference1.ts, 138, 23)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 139, 15)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 139, 10)) } function zip(x: T, y: U): [T, U] { ->zip : Symbol(zip, Decl(genericFunctionInference1.ts, 93, 1)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 94, 13)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 94, 15)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 94, 19)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 94, 13)) ->y : Symbol(y, Decl(genericFunctionInference1.ts, 94, 24)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 94, 15)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 94, 13)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 94, 15)) +>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 140, 1)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 141, 13)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 141, 15)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 141, 19)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 141, 13)) +>y : Symbol(y, Decl(genericFunctionInference1.ts, 141, 24)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 141, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 141, 13)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 141, 15)) return [x, y]; ->x : Symbol(x, Decl(genericFunctionInference1.ts, 94, 19)) ->y : Symbol(y, Decl(genericFunctionInference1.ts, 94, 24)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 141, 19)) +>y : Symbol(y, Decl(genericFunctionInference1.ts, 141, 24)) } var expected: (y: U, x: T) => [T, U] = flip(zip); ->expected : Symbol(expected, Decl(genericFunctionInference1.ts, 98, 3)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 15)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 17)) ->y : Symbol(y, Decl(genericFunctionInference1.ts, 98, 21)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 17)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 98, 26)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 15)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 98, 15)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 98, 17)) ->flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20)) ->zip : Symbol(zip, Decl(genericFunctionInference1.ts, 93, 1)) +>expected : Symbol(expected, Decl(genericFunctionInference1.ts, 145, 3)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 145, 15)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 145, 17)) +>y : Symbol(y, Decl(genericFunctionInference1.ts, 145, 21)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 145, 17)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 145, 26)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 145, 15)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 145, 15)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 145, 17)) +>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 134, 20)) +>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 140, 1)) var actual = flip(zip); ->actual : Symbol(actual, Decl(genericFunctionInference1.ts, 99, 3)) ->flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20)) ->zip : Symbol(zip, Decl(genericFunctionInference1.ts, 93, 1)) +>actual : Symbol(actual, Decl(genericFunctionInference1.ts, 146, 3)) +>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 134, 20)) +>zip : Symbol(zip, Decl(genericFunctionInference1.ts, 140, 1)) // #9366 const map = (transform: (t: T) => U) => ->map : Symbol(map, Decl(genericFunctionInference1.ts, 103, 5)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 103, 13)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 103, 15)) ->transform : Symbol(transform, Decl(genericFunctionInference1.ts, 103, 19)) ->t : Symbol(t, Decl(genericFunctionInference1.ts, 103, 31)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 103, 13)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 103, 15)) +>map : Symbol(map, Decl(genericFunctionInference1.ts, 150, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 150, 13)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 150, 15)) +>transform : Symbol(transform, Decl(genericFunctionInference1.ts, 150, 19)) +>t : Symbol(t, Decl(genericFunctionInference1.ts, 150, 31)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 150, 13)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 150, 15)) (arr: T[]) => arr.map(transform) ->arr : Symbol(arr, Decl(genericFunctionInference1.ts, 104, 5)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 103, 13)) +>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 151, 5)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 150, 13)) >arr.map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) ->arr : Symbol(arr, Decl(genericFunctionInference1.ts, 104, 5)) +>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 151, 5)) >map : Symbol(Array.map, Decl(lib.es5.d.ts, --, --)) ->transform : Symbol(transform, Decl(genericFunctionInference1.ts, 103, 19)) +>transform : Symbol(transform, Decl(genericFunctionInference1.ts, 150, 19)) const identityStr = (t: string) => t; ->identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 106, 5)) ->t : Symbol(t, Decl(genericFunctionInference1.ts, 106, 21)) ->t : Symbol(t, Decl(genericFunctionInference1.ts, 106, 21)) +>identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 153, 5)) +>t : Symbol(t, Decl(genericFunctionInference1.ts, 153, 21)) +>t : Symbol(t, Decl(genericFunctionInference1.ts, 153, 21)) const arr: string[] = map(identityStr)(['a']); ->arr : Symbol(arr, Decl(genericFunctionInference1.ts, 108, 5)) ->map : Symbol(map, Decl(genericFunctionInference1.ts, 103, 5)) ->identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 106, 5)) +>arr : Symbol(arr, Decl(genericFunctionInference1.ts, 155, 5)) +>map : Symbol(map, Decl(genericFunctionInference1.ts, 150, 5)) +>identityStr : Symbol(identityStr, Decl(genericFunctionInference1.ts, 153, 5)) const arr1: string[] = map(identity)(['a']); ->arr1 : Symbol(arr1, Decl(genericFunctionInference1.ts, 109, 5)) ->map : Symbol(map, Decl(genericFunctionInference1.ts, 103, 5)) ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) +>arr1 : Symbol(arr1, Decl(genericFunctionInference1.ts, 156, 5)) +>map : Symbol(map, Decl(genericFunctionInference1.ts, 150, 5)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) // #9949 function of2(one: a, two: b): [a, b] { ->of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 109, 44)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 13)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 113, 15)) ->one : Symbol(one, Decl(genericFunctionInference1.ts, 113, 19)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 13)) ->two : Symbol(two, Decl(genericFunctionInference1.ts, 113, 26)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 113, 15)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 113, 13)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 113, 15)) +>of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 156, 44)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 160, 13)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 160, 15)) +>one : Symbol(one, Decl(genericFunctionInference1.ts, 160, 19)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 160, 13)) +>two : Symbol(two, Decl(genericFunctionInference1.ts, 160, 26)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 160, 15)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 160, 13)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 160, 15)) return [one, two]; ->one : Symbol(one, Decl(genericFunctionInference1.ts, 113, 19)) ->two : Symbol(two, Decl(genericFunctionInference1.ts, 113, 26)) +>one : Symbol(one, Decl(genericFunctionInference1.ts, 160, 19)) +>two : Symbol(two, Decl(genericFunctionInference1.ts, 160, 26)) } const flipped = flip(of2); ->flipped : Symbol(flipped, Decl(genericFunctionInference1.ts, 117, 5)) ->flip : Symbol(flip, Decl(genericFunctionInference1.ts, 87, 20)) ->of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 109, 44)) +>flipped : Symbol(flipped, Decl(genericFunctionInference1.ts, 164, 5)) +>flip : Symbol(flip, Decl(genericFunctionInference1.ts, 134, 20)) +>of2 : Symbol(of2, Decl(genericFunctionInference1.ts, 156, 44)) // #29904.1 type Component

= (props: P) => {}; ->Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 121, 15)) ->props : Symbol(props, Decl(genericFunctionInference1.ts, 121, 21)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 121, 15)) +>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 164, 26)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 168, 15)) +>props : Symbol(props, Decl(genericFunctionInference1.ts, 168, 21)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 168, 15)) declare const myHoc1:

(C: Component

) => Component

; ->myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 123, 13)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 123, 23)) ->C : Symbol(C, Decl(genericFunctionInference1.ts, 123, 26)) ->Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 123, 23)) ->Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 123, 23)) +>myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 170, 13)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 170, 23)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 170, 26)) +>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 164, 26)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 170, 23)) +>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 164, 26)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 170, 23)) declare const myHoc2:

(C: Component

) => Component

; ->myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 124, 13)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 124, 23)) ->C : Symbol(C, Decl(genericFunctionInference1.ts, 124, 26)) ->Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 124, 23)) ->Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26)) ->P : Symbol(P, Decl(genericFunctionInference1.ts, 124, 23)) +>myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 171, 13)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 171, 23)) +>C : Symbol(C, Decl(genericFunctionInference1.ts, 171, 26)) +>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 164, 26)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 171, 23)) +>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 164, 26)) +>P : Symbol(P, Decl(genericFunctionInference1.ts, 171, 23)) declare const MyComponent1: Component<{ foo: 1 }>; ->MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 126, 13)) ->Component : Symbol(Component, Decl(genericFunctionInference1.ts, 117, 26)) ->foo : Symbol(foo, Decl(genericFunctionInference1.ts, 126, 39)) +>MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 173, 13)) +>Component : Symbol(Component, Decl(genericFunctionInference1.ts, 164, 26)) +>foo : Symbol(foo, Decl(genericFunctionInference1.ts, 173, 39)) const enhance = pipe( ->enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 128, 5)) +>enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 175, 5)) >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) myHoc1, ->myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 123, 13)) +>myHoc1 : Symbol(myHoc1, Decl(genericFunctionInference1.ts, 170, 13)) myHoc2, ->myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 124, 13)) +>myHoc2 : Symbol(myHoc2, Decl(genericFunctionInference1.ts, 171, 13)) ); const MyComponent2 = enhance(MyComponent1); ->MyComponent2 : Symbol(MyComponent2, Decl(genericFunctionInference1.ts, 133, 5)) ->enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 128, 5)) ->MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 126, 13)) +>MyComponent2 : Symbol(MyComponent2, Decl(genericFunctionInference1.ts, 180, 5)) +>enhance : Symbol(enhance, Decl(genericFunctionInference1.ts, 175, 5)) +>MyComponent1 : Symbol(MyComponent1, Decl(genericFunctionInference1.ts, 173, 13)) // #29904.2 const fn20 = pipe((_a?: {}) => 1); ->fn20 : Symbol(fn20, Decl(genericFunctionInference1.ts, 137, 5)) +>fn20 : Symbol(fn20, Decl(genericFunctionInference1.ts, 184, 5)) >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) ->_a : Symbol(_a, Decl(genericFunctionInference1.ts, 137, 19)) +>_a : Symbol(_a, Decl(genericFunctionInference1.ts, 184, 19)) // #29904.3 type Fn = (n: number) => number; ->Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 137, 34)) ->n : Symbol(n, Decl(genericFunctionInference1.ts, 141, 11)) +>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 184, 34)) +>n : Symbol(n, Decl(genericFunctionInference1.ts, 188, 11)) const fn30: Fn = pipe( ->fn30 : Symbol(fn30, Decl(genericFunctionInference1.ts, 142, 5)) ->Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 137, 34)) +>fn30 : Symbol(fn30, Decl(genericFunctionInference1.ts, 189, 5)) +>Fn : Symbol(Fn, Decl(genericFunctionInference1.ts, 184, 34)) >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) x => x + 1, ->x : Symbol(x, Decl(genericFunctionInference1.ts, 142, 22)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 142, 22)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 189, 22)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 189, 22)) x => x * 2, ->x : Symbol(x, Decl(genericFunctionInference1.ts, 143, 15)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 143, 15)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 190, 15)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 190, 15)) ); const promise = Promise.resolve(1); ->promise : Symbol(promise, Decl(genericFunctionInference1.ts, 147, 5)) +>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 194, 5)) >Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) >Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) promise.then( >promise.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) ->promise : Symbol(promise, Decl(genericFunctionInference1.ts, 147, 5)) +>promise : Symbol(promise, Decl(genericFunctionInference1.ts, 194, 5)) >then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) pipe( >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) x => x + 1, ->x : Symbol(x, Decl(genericFunctionInference1.ts, 149, 9)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 149, 9)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 196, 9)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 196, 9)) x => x * 2, ->x : Symbol(x, Decl(genericFunctionInference1.ts, 150, 19)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 150, 19)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 197, 19)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 197, 19)) ), ); @@ -797,137 +947,137 @@ promise.then( // #29904.4 declare const getString: () => string; ->getString : Symbol(getString, Decl(genericFunctionInference1.ts, 157, 13)) +>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 204, 13)) declare const orUndefined: (name: string) => string | undefined; ->orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 158, 13)) ->name : Symbol(name, Decl(genericFunctionInference1.ts, 158, 28)) +>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 205, 13)) +>name : Symbol(name, Decl(genericFunctionInference1.ts, 205, 28)) declare const identity: (value: T) => T; ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 159, 25)) ->value : Symbol(value, Decl(genericFunctionInference1.ts, 159, 28)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 159, 25)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 159, 25)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 206, 25)) +>value : Symbol(value, Decl(genericFunctionInference1.ts, 206, 28)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 206, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 206, 25)) const fn40 = pipe( ->fn40 : Symbol(fn40, Decl(genericFunctionInference1.ts, 161, 5)) +>fn40 : Symbol(fn40, Decl(genericFunctionInference1.ts, 208, 5)) >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) getString, ->getString : Symbol(getString, Decl(genericFunctionInference1.ts, 157, 13)) +>getString : Symbol(getString, Decl(genericFunctionInference1.ts, 204, 13)) string => orUndefined(string), ->string : Symbol(string, Decl(genericFunctionInference1.ts, 162, 14)) ->orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 158, 13)) ->string : Symbol(string, Decl(genericFunctionInference1.ts, 162, 14)) +>string : Symbol(string, Decl(genericFunctionInference1.ts, 209, 14)) +>orUndefined : Symbol(orUndefined, Decl(genericFunctionInference1.ts, 205, 13)) +>string : Symbol(string, Decl(genericFunctionInference1.ts, 209, 14)) identity, ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) ); // #29904.6 declare const getArray: () => string[]; ->getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13)) +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 216, 13)) declare const first: (ts: T[]) => T; ->first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 170, 22)) ->ts : Symbol(ts, Decl(genericFunctionInference1.ts, 170, 25)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 170, 22)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 170, 22)) +>first : Symbol(first, Decl(genericFunctionInference1.ts, 217, 13)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 217, 22)) +>ts : Symbol(ts, Decl(genericFunctionInference1.ts, 217, 25)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 217, 22)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 217, 22)) const fn60 = pipe( ->fn60 : Symbol(fn60, Decl(genericFunctionInference1.ts, 172, 5)) +>fn60 : Symbol(fn60, Decl(genericFunctionInference1.ts, 219, 5)) >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) getArray, ->getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13)) +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 216, 13)) x => x, ->x : Symbol(x, Decl(genericFunctionInference1.ts, 173, 13)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 173, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 220, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 220, 13)) first, ->first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13)) +>first : Symbol(first, Decl(genericFunctionInference1.ts, 217, 13)) ); const fn61 = pipe( ->fn61 : Symbol(fn61, Decl(genericFunctionInference1.ts, 178, 5)) +>fn61 : Symbol(fn61, Decl(genericFunctionInference1.ts, 225, 5)) >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) getArray, ->getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13)) +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 216, 13)) identity, ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) first, ->first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13)) +>first : Symbol(first, Decl(genericFunctionInference1.ts, 217, 13)) ); const fn62 = pipe( ->fn62 : Symbol(fn62, Decl(genericFunctionInference1.ts, 184, 5)) +>fn62 : Symbol(fn62, Decl(genericFunctionInference1.ts, 231, 5)) >pipe : Symbol(pipe, Decl(genericFunctionInference1.ts, 0, 0), Decl(genericFunctionInference1.ts, 0, 84), Decl(genericFunctionInference1.ts, 1, 104)) getArray, ->getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 169, 13)) +>getArray : Symbol(getArray, Decl(genericFunctionInference1.ts, 216, 13)) x => x, ->x : Symbol(x, Decl(genericFunctionInference1.ts, 185, 13)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 185, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 232, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 232, 13)) x => first(x), ->x : Symbol(x, Decl(genericFunctionInference1.ts, 186, 11)) ->first : Symbol(first, Decl(genericFunctionInference1.ts, 170, 13)) ->x : Symbol(x, Decl(genericFunctionInference1.ts, 186, 11)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 233, 11)) +>first : Symbol(first, Decl(genericFunctionInference1.ts, 217, 13)) +>x : Symbol(x, Decl(genericFunctionInference1.ts, 233, 11)) ); // Repro from #30297 declare function foo2(fn: T, a?: U, b?: U): [T, U]; ->foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22)) ->fn : Symbol(fn, Decl(genericFunctionInference1.ts, 192, 32)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22)) ->a : Symbol(a, Decl(genericFunctionInference1.ts, 192, 38)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24)) ->b : Symbol(b, Decl(genericFunctionInference1.ts, 192, 45)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 192, 22)) ->U : Symbol(U, Decl(genericFunctionInference1.ts, 192, 24)) +>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 235, 2)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 239, 22)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 239, 24)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 239, 22)) +>fn : Symbol(fn, Decl(genericFunctionInference1.ts, 239, 32)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 239, 22)) +>a : Symbol(a, Decl(genericFunctionInference1.ts, 239, 38)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 239, 24)) +>b : Symbol(b, Decl(genericFunctionInference1.ts, 239, 45)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 239, 24)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 239, 22)) +>U : Symbol(U, Decl(genericFunctionInference1.ts, 239, 24)) foo2(() => {}); ->foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2)) +>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 235, 2)) foo2(identity); ->foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2)) ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) +>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 235, 2)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) foo2(identity, 1); ->foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 188, 2)) ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) +>foo2 : Symbol(foo2, Decl(genericFunctionInference1.ts, 235, 2)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) // Repro from #30324 declare function times(fn: (i: number) => T): (n: number) => T[]; ->times : Symbol(times, Decl(genericFunctionInference1.ts, 196, 18)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 200, 23)) ->fn : Symbol(fn, Decl(genericFunctionInference1.ts, 200, 26)) ->i : Symbol(i, Decl(genericFunctionInference1.ts, 200, 31)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 200, 23)) ->n : Symbol(n, Decl(genericFunctionInference1.ts, 200, 50)) ->T : Symbol(T, Decl(genericFunctionInference1.ts, 200, 23)) +>times : Symbol(times, Decl(genericFunctionInference1.ts, 243, 18)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 247, 23)) +>fn : Symbol(fn, Decl(genericFunctionInference1.ts, 247, 26)) +>i : Symbol(i, Decl(genericFunctionInference1.ts, 247, 31)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 247, 23)) +>n : Symbol(n, Decl(genericFunctionInference1.ts, 247, 50)) +>T : Symbol(T, Decl(genericFunctionInference1.ts, 247, 23)) const a2 = times(identity)(5); // => [0, 1, 2, 3, 4] ->a2 : Symbol(a2, Decl(genericFunctionInference1.ts, 201, 5)) ->times : Symbol(times, Decl(genericFunctionInference1.ts, 196, 18)) ->identity : Symbol(identity, Decl(genericFunctionInference1.ts, 159, 13)) +>a2 : Symbol(a2, Decl(genericFunctionInference1.ts, 248, 5)) +>times : Symbol(times, Decl(genericFunctionInference1.ts, 243, 18)) +>identity : Symbol(identity, Decl(genericFunctionInference1.ts, 206, 13)) diff --git a/tests/baselines/reference/genericFunctionInference1.types b/tests/baselines/reference/genericFunctionInference1.types index a78d20c133957..1974fe17bea80 100644 --- a/tests/baselines/reference/genericFunctionInference1.types +++ b/tests/baselines/reference/genericFunctionInference1.types @@ -443,6 +443,150 @@ let f60 = wrap3(baz); >wrap3 : (f: (a: A, b1: B, b2: B) => C) => (a: A, b1: B, b2: B) => C >baz : (t1: T, t2: T, u: U) => [T, U] +declare const list2: { +>list2 : { (a: T): T[]; foo: string; bar(): number; } + + (a: T): T[]; +>a : T + + foo: string; +>foo : string + + bar(): number; +>bar : () => number +} + +let f70 = pipe(list2, box); +>f70 : (a: T) => { value: T[]; } +>pipe(list2, box) : (a: T) => { value: T[]; } +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>list2 : { (a: T): T[]; foo: string; bar(): number; } +>box : (x: V) => { value: V; } + +let f71 = pipe(box, list2); +>f71 : (x: V) => { value: V; }[] +>pipe(box, list2) : (x: V) => { value: V; }[] +>pipe : { (ab: (...args: A) => B): (...args: A) => B; (ab: (...args: A) => B, bc: (b: B) => C): (...args: A) => C; (ab: (...args: A) => B, bc: (b: B) => C, cd: (c: C) => D): (...args: A) => D; } +>box : (x: V) => { value: V; } +>list2 : { (a: T): T[]; foo: string; bar(): number; } + +declare class Point { +>Point : Point + + constructor(x: number, y: number); +>x : number +>y : number + + readonly x: number; +>x : number + + readonly y: number; +>y : number +} + +declare class Bag { +>Bag : Bag + + constructor(...args: T[]); +>args : T[] + + contains(value: T): boolean; +>contains : (value: T) => boolean +>value : T + + static foo: string; +>foo : string +} + +function asFunction(cf: new (...args: A) => B) { +>asFunction : (cf: new (...args: A) => B) => (...args: A) => B +>cf : new (...args: A) => B +>args : A + + return (...args: A) => new cf(...args); +>(...args: A) => new cf(...args) : (...args: A) => B +>args : A +>new cf(...args) : B +>cf : new (...args: A) => B +>...args : any +>args : A +} + +const newPoint = asFunction(Point); +>newPoint : (x: number, y: number) => Point +>asFunction(Point) : (x: number, y: number) => Point +>asFunction : (cf: new (...args: A) => B) => (...args: A) => B +>Point : typeof Point + +const newBag = asFunction(Bag); +>newBag : (...args: T[]) => Bag +>asFunction(Bag) : (...args: T[]) => Bag +>asFunction : (cf: new (...args: A) => B) => (...args: A) => B +>Bag : typeof Bag + +const p1 = new Point(10, 20); +>p1 : Point +>new Point(10, 20) : Point +>Point : typeof Point +>10 : 10 +>20 : 20 + +const p2 = newPoint(10, 20); +>p2 : Point +>newPoint(10, 20) : Point +>newPoint : (x: number, y: number) => Point +>10 : 10 +>20 : 20 + +const bag1 = new Bag(1, 2, 3); +>bag1 : Bag +>new Bag(1, 2, 3) : Bag +>Bag : typeof Bag +>1 : 1 +>2 : 2 +>3 : 3 + +const bag2 = newBag('a', 'b', 'c'); +>bag2 : Bag +>newBag('a', 'b', 'c') : Bag +>newBag : (...args: T[]) => Bag +>'a' : "a" +>'b' : "b" +>'c' : "c" + +declare class Comp

{ +>Comp : Comp

+ + props: P; +>props : P + + constructor(props: P); +>props : P +} + +type CompClass

= new (props: P) => Comp

; +>CompClass : CompClass

+>props : P + +declare function myHoc

(C: CompClass

): CompClass

; +>myHoc :

(C: CompClass

) => CompClass

+>C : CompClass

+ +type GenericProps = { foo: number, stuff: T }; +>GenericProps : GenericProps +>foo : number +>stuff : T + +declare class GenericComp extends Comp> {} +>GenericComp : GenericComp +>Comp : Comp> + +const GenericComp2 = myHoc(GenericComp); +>GenericComp2 : new (props: GenericProps) => Comp> +>myHoc(GenericComp) : new (props: GenericProps) => Comp> +>myHoc :

(C: CompClass

) => CompClass

+>GenericComp : typeof GenericComp + // #417 function mirror(f: (a: A) => B): (a: A) => B { return f; }