This repository was archived by the owner on Nov 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +28
-8
lines changed
examples/typescript-react-example/src Expand file tree Collapse file tree 5 files changed +28
-8
lines changed Original file line number Diff line number Diff line change 11# master
2+ - TypeScript: type children of imported components as ` React.ReactNode ` .
23
34# 4.2.0
45- Add basic support for inherited type definitions in polymorphic variants e.g. ` type color = [red | blue] ` . No support for conversion at the moment.
Original file line number Diff line number Diff line change @@ -9,28 +9,28 @@ import {default as defaultNotChecked} from './hookExample';
99// In case of type error, check the type of 'make' in 'ImportHookDefault.re' and './hookExample'.
1010export const makeTypeChecked : React . ComponentType < {
1111 readonly person : person ;
12- readonly children : JSX . Element ;
12+ readonly children : React . ReactNode ;
1313 readonly renderMe : ImportHooks_renderMe < string >
1414} > = makeNotChecked ;
1515
1616// Export 'make' early to allow circular import from the '.bs.js' file.
1717export const make : unknown = makeTypeChecked as React . ComponentType < {
1818 readonly person : person ;
19- readonly children : JSX . Element ;
19+ readonly children : React . ReactNode ;
2020 readonly renderMe : ImportHooks_renderMe < string >
2121} > ;
2222
2323// In case of type error, check the type of 'default' in 'ImportHookDefault.re' and './hookExample'.
2424export const defaultTypeChecked : React . ComponentType < {
2525 readonly person : person ;
26- readonly children : JSX . Element ;
26+ readonly children : React . ReactNode ;
2727 readonly renderMe : ImportHooks_renderMe < string >
2828} > = defaultNotChecked ;
2929
3030// Export '$$default' early to allow circular import from the '.bs.js' file.
3131export const $$default : unknown = defaultTypeChecked as React . ComponentType < {
3232 readonly person : person ;
33- readonly children : JSX . Element ;
33+ readonly children : React . ReactNode ;
3434 readonly renderMe : ImportHooks_renderMe < string >
3535} > ;
3636
Original file line number Diff line number Diff line change @@ -9,14 +9,14 @@ import {foo as fooNotChecked} from './hookExample';
99// In case of type error, check the type of 'makeRenamed' in 'ImportHooks.re' and './hookExample'.
1010export const makeRenamedTypeChecked : React . ComponentType < {
1111 readonly person : person ;
12- readonly children : JSX . Element ;
12+ readonly children : React . ReactNode ;
1313 readonly renderMe : renderMe < any >
1414} > = makeRenamedNotChecked ;
1515
1616// Export 'makeRenamed' early to allow circular import from the '.bs.js' file.
1717export const makeRenamed : unknown = makeRenamedTypeChecked as React . ComponentType < {
1818 readonly person : person ;
19- readonly children : JSX . Element ;
19+ readonly children : React . ReactNode ;
2020 readonly renderMe : renderMe < any >
2121} > ;
2222
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export const foo = (x: {
66
77type Props = {
88 readonly person : { readonly name : string ; readonly age : number } ;
9- readonly children : JSX . Element ;
9+ readonly children : React . ReactNode ;
1010 readonly renderMe : React . ComponentType < {
1111 randomString : string ;
1212 readonly poly : string ;
Original file line number Diff line number Diff line change @@ -174,11 +174,30 @@ let rec emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
174174 let type_ =
175175 match type_ with
176176 | Function
177- ({argTypes = [{aType = Object (_, fields)}]; retType} as function_)
177+ ({
178+ argTypes = [({aType = Object (closedFlag, fields)} as argType)];
179+ retType;
180+ } as function_)
178181 when retType |> EmitType. isTypeFunctionComponent ~config ~fields ->
179182 let componentName =
180183 match importFile with "." | ".." -> None | _ -> Some importFile
181184 in
185+ let fields =
186+ fields
187+ |> List. map (fun (field : field ) ->
188+ match
189+ field.nameJS = " children"
190+ && field.type_ |> EmitType. isTypeReactElement ~config
191+ with
192+ | true -> {field with type_ = EmitType. typeReactChild ~config }
193+ | false -> field)
194+ in
195+ let function_ =
196+ {
197+ function_ with
198+ argTypes = [{argType with aType = Object (closedFlag, fields)}];
199+ }
200+ in
182201 Function {function_ with componentName}
183202 | _ -> type_
184203 in
You can’t perform that action at this time.
0 commit comments