-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathsingle-spa-react.test-d.ts
89 lines (77 loc) · 2.48 KB
/
single-spa-react.test-d.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from "react";
import * as ReactDOMClient from "react-dom/client";
import "../types/single-spa-react";
import singleSpaReact, {
ReactAppOrParcel,
SingleSpaContext,
} from "../types/single-spa-react";
import Parcel, { ParcelCompProps } from "../types/parcel";
import { AppProps, LifeCycleFn, mountRootParcel } from "single-spa";
import { expectType } from "tsd";
class ErrorBoundary extends React.Component<AppProps & any, ErrorState> {
render() {
return React.createElement("div", null, "hi");
}
componentDidCatch(err: Error, errInfo: React.ErrorInfo) {}
}
interface ErrorState {}
const lifecylesUntypedProps = singleSpaReact({
React,
ReactDOMClient,
rootComponent: (props) => React.createElement("div", null, "hi"),
suppressComponentDidCatchWarning: false,
parcelCanUpdate: true,
errorBoundaryClass: ErrorBoundary,
renderType: "createRoot",
});
singleSpaReact({
React,
ReactDOMClient,
loadRootComponent: () =>
Promise.resolve((props) => React.createElement("div", null, "hi")),
});
const lifecycles1 = singleSpaReact<Hi>({
React,
ReactDOMClient,
rootComponent: (props: AppProps & Hi) =>
React.createElement("div", null, "hi"),
domElementGetter(props: Hi & AppProps) {
return document.getElementById(props.name) as HTMLElement;
},
errorBoundary(err: Error, errInfo: React.ErrorInfo, props: AppProps & Hi) {
return React.createElement("div", null, "An error occurred");
},
});
expectType<ReactAppOrParcel<Hi>>(lifecycles1);
expectType<LifeCycleFn<Hi>>(lifecycles1.bootstrap);
expectType<LifeCycleFn<Hi>>(lifecycles1.mount);
expectType<LifeCycleFn<Hi>>(lifecycles1.unmount);
expectType<LifeCycleFn<Hi> | undefined>(lifecycles1.update);
type Hi = {
hi: string;
};
React.createElement<ParcelCompProps<Hi>>(Parcel, {
config: lifecycles1,
mountParcel: mountRootParcel,
wrapWith: "div",
wrapStyle: { backgroundColor: "red" },
wrapClassName: "blue",
appendTo: document.createElement("div"),
parcelDidMount() {},
handleError(err: Error) {},
hi: "there",
});
React.createElement(Parcel, {
config: lifecylesUntypedProps,
});
React.createElement(Parcel, {
config: lifecylesUntypedProps,
hi: "there",
});
const context1 = React.useContext(SingleSpaContext);
const context2 = React.useContext(SingleSpaContext) as AppProps & Hi;
expectType<string>(context1.name);
expectType<any>(context1.singleSpa);
expectType<AppProps["mountParcel"]>(context1.mountParcel);
expectType<any>(context1.customProp);
expectType<string>(context2.hi);