Skip to content

Commit dcaa3bf

Browse files
imdreamrunnermeta-codesync[bot]
authored andcommitted
Improve EntryPoint typing
Differential Revision: D86460323 fbshipit-source-id: 1fcac294d3eb2223b29a71f3c603c096247c743c
1 parent 3ec0b83 commit dcaa3bf

File tree

2 files changed

+36
-55
lines changed

2 files changed

+36
-55
lines changed

packages/react-relay/relay-hooks/EntryPointTypes.flow.js

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -126,37 +126,21 @@ Every .entrypoint file it's an object that must have two required fields:
126126
TEntryPointParams - object that contains all necessary information to execute
127127
the preloaders (routeParams, query variables)
128128
129-
TPreloadedQueries - queries, defined in the root components
130-
131-
TPreloadedEntryPoints - nested entry points, defined in the root components
132-
133-
TRuntimeProps - the type of additional props that you may pass to the
134-
component (like `onClick` handler, etc) during runtime. Values for them
135-
defined during component runtime
136-
137-
TExtraProps - a bag of extra props that you may define in `entrypoint` file
138-
and they will be passed to the EntryPointComponent as `extraProps`
129+
TEntryPointComponent - the root components
139130
*/
140-
export type InternalEntryPointRepresentation<
131+
export type EntryPoint<
141132
-TEntryPointParams,
142-
TPreloadedQueries,
143-
TPreloadedEntryPoints = {...},
144-
TRuntimeProps = {...},
145-
TExtraProps = null,
146-
+TRenders: React.Node = React.Node,
133+
// $FlowExpectedError[unclear-type] accepts any root component
134+
+TEntryPointComponent: EntryPointComponent<any, any, any, any, any>,
147135
> = $ReadOnly<{
148136
getPreloadProps: (
149137
entryPointParams: TEntryPointParams,
150-
) => PreloadProps<TPreloadedQueries, TPreloadedEntryPoints, TExtraProps>,
151-
root: JSResourceReference<
152-
EntryPointComponent<
153-
TPreloadedQueries,
154-
TPreloadedEntryPoints,
155-
TRuntimeProps,
156-
TExtraProps,
157-
TRenders,
158-
>,
138+
) => PreloadProps<
139+
ElementConfig<TEntryPointComponent>['queries'],
140+
ElementConfig<TEntryPointComponent>['entryPoints'],
141+
ElementConfig<TEntryPointComponent>['extraProps'],
159142
>,
143+
root: JSResourceReference<TEntryPointComponent>,
160144
}>;
161145

162146
// The shape of the props of the entry point `root` component
@@ -172,7 +156,23 @@ export type EntryPointProps<
172156
queries: TPreloadedQueries,
173157
}>;
174158

175-
// Type of the entry point `root` component
159+
/**
160+
Type of the entry point `root` component
161+
162+
TEntryPointParams - object that contains all necessary information to execute
163+
the preloaders (routeParams, query variables)
164+
165+
TPreloadedQueries - queries, defined in the root components
166+
167+
TPreloadedEntryPoints - nested entry points, defined in the root components
168+
169+
TRuntimeProps - the type of additional props that you may pass to the
170+
component (like `onClick` handler, etc) during runtime. Values for them
171+
defined during component runtime
172+
173+
TExtraProps - a bag of extra props that you may define in `entrypoint` file
174+
and they will be passed to the EntryPointComponent as `extraProps`
175+
*/
176176
export type EntryPointComponent<
177177
TPreloadedQueries,
178178
TPreloadedEntryPoints = {},
@@ -215,21 +215,18 @@ export type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{
215215
}>;
216216

217217
export type EntryPointElementConfig<
218-
// $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
219-
+TEntryPoint: InternalEntryPointRepresentation<any, any, any, any, any>,
220-
> =
221-
TEntryPoint extends InternalEntryPointRepresentation<
218+
+TEntryPoint: EntryPoint<
222219
// $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
223220
any,
224221
// $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
225222
any,
226-
// $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
227-
any,
228-
infer Props,
229-
// $FlowExpectedError[unclear-type] Need any to make it supertype of all InternalEntryPointRepresentation
230-
any,
223+
>,
224+
> =
225+
TEntryPoint extends EntryPoint<
226+
infer _EntryPointParams,
227+
infer EntryPointComponent,
231228
>
232-
? Props
229+
? ElementConfig<EntryPointComponent>['props']
233230
: empty;
234231

235232
export type ThinQueryParams<
@@ -280,20 +277,10 @@ export type ExtractQueryTypes<
280277
};
281278

282279
// $FlowFixMe[unclear-type]: we don't care about the props
283-
type Renders<+C: component(...any)> =
280+
export type RootComponentRenders<+C: component(...any)> =
284281
// $FlowFixMe[unclear-type]: we don't care about the props
285282
C extends component(...any) renders infer R extends React.Node ? R : empty;
286283

287-
export type EntryPoint<-TEntryPointParams, +TEntryPointComponent> =
288-
InternalEntryPointRepresentation<
289-
TEntryPointParams,
290-
ElementConfig<TEntryPointComponent>['queries'],
291-
ElementConfig<TEntryPointComponent>['entryPoints'],
292-
ElementConfig<TEntryPointComponent>['props'],
293-
ElementConfig<TEntryPointComponent>['extraProps'],
294-
Renders<TEntryPointComponent>,
295-
>;
296-
297284
export type PreloadParamsOf<T> = Parameters<T['getPreloadProps']>[0];
298285

299286
export type IEnvironmentProvider<TOptions> = $ReadOnly<{

packages/react-relay/relay-hooks/NestedRelayEntryPointBuilderUtils.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'use strict';
1313

1414
import type {
15-
InternalEntryPointRepresentation,
15+
EntryPoint,
1616
ThinNestedEntryPointParams,
1717
} from './EntryPointTypes.flow';
1818

@@ -26,13 +26,7 @@ import type {
2626
*/
2727
declare function NestedRelayEntryPoint<TEntryPointParams>(
2828
$ReadOnly<{
29-
entryPoint: InternalEntryPointRepresentation<
30-
TEntryPointParams,
31-
$FlowFixMe,
32-
$FlowFixMe,
33-
$FlowFixMe,
34-
$FlowFixMe,
35-
>,
29+
entryPoint: EntryPoint<TEntryPointParams, $FlowFixMe>,
3630
entryPointParams: TEntryPointParams,
3731
}>,
3832
): ThinNestedEntryPointParams;

0 commit comments

Comments
 (0)