Skip to content

Commit 7d02240

Browse files
vikr01facebook-github-bot
authored andcommittedOct 21, 2020
Create type utility EntryPointElementConfig
Reviewed By: rbalicki2 Differential Revision: D24191021 fbshipit-source-id: ddd50ce144e0cf4623ac916ba8361fed6b3be32e
1 parent 77fc2d7 commit 7d02240

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
 

‎packages/relay-experimental/EntryPointTypes.flow.js

+18
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ export type PreloadedEntryPoint<TEntryPointComponent> = $ReadOnly<{|
210210
rootModuleID: string,
211211
|}>;
212212

213+
type _ComponentFromEntryPoint = <
214+
+TPreloadParams,
215+
+TComponent,
216+
+TEntryPoint: EntryPoint<TPreloadParams, TComponent>,
217+
>(
218+
TEntryPoint,
219+
) => TComponent;
220+
221+
type ComponentFromEntryPoint<+TEntryPoint> = $Call<
222+
_ComponentFromEntryPoint,
223+
TEntryPoint,
224+
>;
225+
226+
export type EntryPointElementConfig<+TEntryPoint> = $PropertyType<
227+
ElementConfig<ComponentFromEntryPoint<TEntryPoint>>,
228+
'props',
229+
>;
230+
213231
export type ThinQueryParams<
214232
TQuery: OperationType,
215233
TEnvironmentProviderOptions,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails oncall+relay
8+
* @flow strict-local
9+
* @format
10+
*/
11+
12+
'use strict';
13+
14+
import type {
15+
EntryPoint,
16+
EntryPointProps,
17+
EntryPointElementConfig,
18+
} from '../EntryPointTypes.flow';
19+
20+
type MyComponentOtherProps = $ReadOnly<{|
21+
foo: string,
22+
|}>;
23+
24+
type MyComponentProps = EntryPointProps<{}, {}, MyComponentOtherProps, {}>;
25+
26+
const MyComponent = (_props: MyComponentProps) => null;
27+
28+
type PreloadParams = $ReadOnly<{||}>;
29+
30+
type MyComponentEntryPointType = EntryPoint<PreloadParams, typeof MyComponent>;
31+
32+
// This gets the "other props" of the component through the entrypoint's typing
33+
type MyComponentEntryPointProps = EntryPointElementConfig<MyComponentEntryPointType>;
34+
35+
// This gets the "other props" directly from the component's prop typings
36+
type OtherProps = $PropertyType<MyComponentProps, 'props'>;
37+
38+
// We want to make sure that `OtherProps` and `MyComponentEntryPointProps` are exactly the same.
39+
opaque type __SUBTYPE_CHECK_1__: OtherProps = MyComponentEntryPointProps;
40+
opaque type __SUBTYPE_CHECK_2__: MyComponentEntryPointProps = OtherProps;
41+
42+
({foo: ''}: OtherProps);
43+
44+
({foo: ''}: MyComponentEntryPointProps);
45+
46+
// $FlowExpectedError[incompatible-cast]
47+
({foo: null}: MyComponentEntryPointProps);

0 commit comments

Comments
 (0)
Please sign in to comment.