=== tests/cases/compiler/promiseChaining.ts === class Chain { >Chain : Chain >T : T constructor(public value: T) { } >value : T >T : T then(cb: (x: T) => S): Chain { >then : (cb: (x: T) => S) => Chain >S : S >cb : (x: T) => S >x : T >T : T >S : S >Chain : Chain >S : S var result = cb(this.value); >result : S >cb(this.value) : S >cb : (x: T) => S >this.value : T >this : Chain >value : T // should get a fresh type parameter which each then call var z = this.then(x => result)/*S*/.then(x => "abc")/*string*/.then(x => x.length)/*number*/; // No error >z : Chain >this.then(x => result)/*S*/.then(x => "abc")/*string*/.then(x => x.length) : Chain >this.then(x => result)/*S*/.then(x => "abc")/*string*/.then : (cb: (x: string) => S) => Chain >this.then(x => result)/*S*/.then(x => "abc") : Chain >this.then(x => result)/*S*/.then : (cb: (x: S) => S) => Chain >this.then(x => result) : Chain >this.then : (cb: (x: T) => S) => Chain >this : Chain >then : (cb: (x: T) => S) => Chain >x => result : (x: T) => S >x : T >result : S >then : (cb: (x: S) => S) => Chain >x => "abc" : (x: S) => string >x : S >then : (cb: (x: string) => S) => Chain >x => x.length : (x: string) => number >x : string >x.length : number >x : string >length : number return new Chain(result); >new Chain(result) : Chain >Chain : typeof Chain >result : S } }