mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Adding tests
This commit is contained in:
parent
87b562c5dc
commit
c00ee42b11
@ -0,0 +1,39 @@
|
||||
//// [contextualSignatureInstantiation.ts]
|
||||
// TypeScript Spec, section 4.12.2:
|
||||
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
|
||||
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
|
||||
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
|
||||
// to a function type with e's call signature instantiated in the context of T<>s call signature (section 3.8.5).
|
||||
|
||||
declare function foo<T>(cb: (x: number, y: string) => T): T;
|
||||
declare function bar<T, U, V>(x: T, y: U, cb: (x: T, y: U) => V): V;
|
||||
|
||||
declare function f(x: number, y: string): boolean;
|
||||
declare function g<T>(x: T, y: T): T;
|
||||
|
||||
var a: boolean;
|
||||
var a = foo(f); // Should be boolean
|
||||
|
||||
var b: number | string;
|
||||
var b = foo(g); // Should be number | string
|
||||
var b = bar(1, "one", g); // Should be number | string
|
||||
var b = bar("one", 1, g); // Should be number | string
|
||||
|
||||
var c: number;
|
||||
var c = bar(1, 1, g); // Should be number
|
||||
|
||||
|
||||
//// [contextualSignatureInstantiation.js]
|
||||
// TypeScript Spec, section 4.12.2:
|
||||
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
|
||||
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
|
||||
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
|
||||
// to a function type with e's call signature instantiated in the context of T<>s call signature (section 3.8.5).
|
||||
var a;
|
||||
var a = foo(f); // Should be boolean
|
||||
var b;
|
||||
var b = foo(g); // Should be number | string
|
||||
var b = bar(1, "one", g); // Should be number | string
|
||||
var b = bar("one", 1, g); // Should be number | string
|
||||
var c;
|
||||
var c = bar(1, 1, g); // Should be number
|
||||
@ -0,0 +1,86 @@
|
||||
=== tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts ===
|
||||
// TypeScript Spec, section 4.12.2:
|
||||
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
|
||||
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
|
||||
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
|
||||
// to a function type with e's call signature instantiated in the context of T<>s call signature (section 3.8.5).
|
||||
|
||||
declare function foo<T>(cb: (x: number, y: string) => T): T;
|
||||
>foo : <T>(cb: (x: number, y: string) => T) => T
|
||||
>T : T
|
||||
>cb : (x: number, y: string) => T
|
||||
>x : number
|
||||
>y : string
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
declare function bar<T, U, V>(x: T, y: U, cb: (x: T, y: U) => V): V;
|
||||
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
|
||||
>T : T
|
||||
>U : U
|
||||
>V : V
|
||||
>x : T
|
||||
>T : T
|
||||
>y : U
|
||||
>U : U
|
||||
>cb : (x: T, y: U) => V
|
||||
>x : T
|
||||
>T : T
|
||||
>y : U
|
||||
>U : U
|
||||
>V : V
|
||||
>V : V
|
||||
|
||||
declare function f(x: number, y: string): boolean;
|
||||
>f : (x: number, y: string) => boolean
|
||||
>x : number
|
||||
>y : string
|
||||
|
||||
declare function g<T>(x: T, y: T): T;
|
||||
>g : <T>(x: T, y: T) => T
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>y : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
var a: boolean;
|
||||
>a : boolean
|
||||
|
||||
var a = foo(f); // Should be boolean
|
||||
>a : boolean
|
||||
>foo(f) : boolean
|
||||
>foo : <T>(cb: (x: number, y: string) => T) => T
|
||||
>f : (x: number, y: string) => boolean
|
||||
|
||||
var b: number | string;
|
||||
>b : string | number
|
||||
|
||||
var b = foo(g); // Should be number | string
|
||||
>b : string | number
|
||||
>foo(g) : string | number
|
||||
>foo : <T>(cb: (x: number, y: string) => T) => T
|
||||
>g : <T>(x: T, y: T) => T
|
||||
|
||||
var b = bar(1, "one", g); // Should be number | string
|
||||
>b : string | number
|
||||
>bar(1, "one", g) : string | number
|
||||
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
|
||||
>g : <T>(x: T, y: T) => T
|
||||
|
||||
var b = bar("one", 1, g); // Should be number | string
|
||||
>b : string | number
|
||||
>bar("one", 1, g) : string | number
|
||||
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
|
||||
>g : <T>(x: T, y: T) => T
|
||||
|
||||
var c: number;
|
||||
>c : number
|
||||
|
||||
var c = bar(1, 1, g); // Should be number
|
||||
>c : number
|
||||
>bar(1, 1, g) : number
|
||||
>bar : <T, U, V>(x: T, y: U, cb: (x: T, y: U) => V) => V
|
||||
>g : <T>(x: T, y: T) => T
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
// TypeScript Spec, section 4.12.2:
|
||||
// If e is an expression of a function type that contains exactly one generic call signature and no other members,
|
||||
// and T is a function type with exactly one non - generic call signature and no other members, then any inferences
|
||||
// made for type parameters referenced by the parameters of T's call signature are fixed, and e's type is changed
|
||||
// to a function type with e's call signature instantiated in the context of T’s call signature (section 3.8.5).
|
||||
|
||||
declare function foo<T>(cb: (x: number, y: string) => T): T;
|
||||
declare function bar<T, U, V>(x: T, y: U, cb: (x: T, y: U) => V): V;
|
||||
|
||||
declare function f(x: number, y: string): boolean;
|
||||
declare function g<T>(x: T, y: T): T;
|
||||
|
||||
var a: boolean;
|
||||
var a = foo(f); // Should be boolean
|
||||
|
||||
var b: number | string;
|
||||
var b = foo(g); // Should be number | string
|
||||
var b = bar(1, "one", g); // Should be number | string
|
||||
var b = bar("one", 1, g); // Should be number | string
|
||||
|
||||
var c: number;
|
||||
var c = bar(1, 1, g); // Should be number
|
||||
Loading…
x
Reference in New Issue
Block a user