forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcircularlySimplifyingConditionalTypesNoCrash.js
55 lines (47 loc) · 1.94 KB
/
circularlySimplifyingConditionalTypesNoCrash.js
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
54
55
//// [circularlySimplifyingConditionalTypesNoCrash.ts]
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
type Shared< // Circularly self constraining type, defered thanks to mapping
InjectedProps,
DecorationTargetProps extends Shared<InjectedProps, DecorationTargetProps>
> = {
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
};
interface ComponentClass<P> {
defaultProps?: Partial<P>; // Inference target is also mapped _and_ optional
}
interface InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> {
<P extends Shared<TInjectedProps, P>>(
component: ComponentClass<P>
): ComponentClass<Omit<P, keyof Shared<TInjectedProps, P>> & TNeedsProps> & { WrappedComponent: ComponentClass<P> }
} // Then intersected with and indexed via Omit and &
interface Connect { // Then strictly compared with another signature in its context
<TStateProps, TOwnProps>(
mapStateToProps: unknown,
): InferableComponentEnhancerWithProps<TStateProps, TOwnProps>;
<TDispatchProps, TOwnProps>(
mapStateToProps: null | undefined,
mapDispatchToProps: unknown,
mergeProps: null | undefined,
options: unknown
): InferableComponentEnhancerWithProps<TDispatchProps, TOwnProps>;
}
declare var connect: Connect;
const myStoreConnect: Connect = function(
mapStateToProps?: any,
mapDispatchToProps?: any,
mergeProps?: any,
options: unknown = {},
) {
return connect(
mapStateToProps,
mapDispatchToProps,
mergeProps,
options,
);
};
//// [circularlySimplifyingConditionalTypesNoCrash.js]
"use strict";
var myStoreConnect = function (mapStateToProps, mapDispatchToProps, mergeProps, options) {
if (options === void 0) { options = {}; }
return connect(mapStateToProps, mapDispatchToProps, mergeProps, options);
};