forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgenericCallWithinOwnBodyCastTypeParameterIdentity.js
More file actions
52 lines (47 loc) · 1.52 KB
/
genericCallWithinOwnBodyCastTypeParameterIdentity.js
File metadata and controls
52 lines (47 loc) · 1.52 KB
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
//// [tests/cases/compiler/genericCallWithinOwnBodyCastTypeParameterIdentity.ts] ////
//// [genericCallWithinOwnBodyCastTypeParameterIdentity.ts]
interface Thenable<Value> {
then<V>(
onFulfilled: (value: Value) => V | Thenable<V>,
): Thenable<V>;
}
const toThenable = <Result, Input>(fn: (input: Input) => Result | Thenable<Result>) =>
(input: Input): Thenable<Result> => {
const result = fn(input)
return {
then<V>(onFulfilled: (value: Result) => V | Thenable<V>) {
return toThenable<V, Result>(onFulfilled)(result as Result)
}
};
}
const toThenableInferred = <Result, Input>(fn: (input: Input) => Result | Thenable<Result>) =>
(input: Input): Thenable<Result> => {
const result = fn(input)
return {
then(onFulfilled) {
return toThenableInferred(onFulfilled)(result as Result)
}
};
}
//// [genericCallWithinOwnBodyCastTypeParameterIdentity.js]
"use strict";
var toThenable = function (fn) {
return function (input) {
var result = fn(input);
return {
then: function (onFulfilled) {
return toThenable(onFulfilled)(result);
}
};
};
};
var toThenableInferred = function (fn) {
return function (input) {
var result = fn(input);
return {
then: function (onFulfilled) {
return toThenableInferred(onFulfilled)(result);
}
};
};
};