1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
=== tests/cases/compiler/promiseChaining1.ts ===
// same example but with constraints on each type parameter
class Chain2<T extends { length: number }> {
>Chain2 : Chain2<T>
>length : number
constructor(public value: T) { }
>value : T
then<S extends Function>(cb: (x: T) => S): Chain2<S> {
>then : <S extends Function>(cb: (x: T) => S) => Chain2<S>
>cb : (x: T) => S
>x : T
var result = cb(this.value);
>result : S
>cb(this.value) : S
>cb : (x: T) => S
>this.value : T
>this : this
>value : T
// should get a fresh type parameter which each then call
var z = this.then(x => result)/*S*/.then(x => "abc")/*Function*/.then(x => x.length)/*number*/; // Should error on "abc" because it is not a Function
>z : Chain2<Function>
>this.then(x => result)/*S*/.then(x => "abc")/*Function*/.then(x => x.length) : Chain2<Function>
>this.then(x => result)/*S*/.then(x => "abc")/*Function*/.then : <S extends Function>(cb: (x: Function) => S) => Chain2<S>
>this.then(x => result)/*S*/.then(x => "abc") : Chain2<Function>
>this.then(x => result)/*S*/.then : <S extends Function>(cb: (x: S) => S) => Chain2<S>
>this.then(x => result) : Chain2<S>
>this.then : <S extends Function>(cb: (x: T) => S) => Chain2<S>
>this : this
>then : <S extends Function>(cb: (x: T) => S) => Chain2<S>
>x => result : (x: T) => S
>x : T
>result : S
>then : <S extends Function>(cb: (x: S) => S) => Chain2<S>
>x => "abc" : (x: S) => string
>x : S
>"abc" : "abc"
>then : <S extends Function>(cb: (x: Function) => S) => Chain2<S>
>x => x.length : (x: Function) => number
>x : Function
>x.length : number
>x : Function
>length : number
return new Chain2(result);
>new Chain2(result) : Chain2<S>
>Chain2 : typeof Chain2
>result : S
}
}
|