Skip to content

Commit 2d48f25

Browse files
committed
More elaborate example of component import.
1 parent 9447c07 commit 2d48f25

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

jscomp/gentype_tests/typescript-react-example/src/JSXV4.bs.js

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/src/JSXV4.gen.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
/* eslint-disable import/first */
33

44

5-
import {foo as fooNotChecked} from './hookExample';
5+
import {make as makeNotChecked} from './hookExample';
66

77
import * as React from 'react';
88

9-
// In case of type error, check the type of 'foo' in 'JSXV4.re' and './hookExample'.
10-
export const fooTypeChecked: (_1:{ readonly person: person }) => string = fooNotChecked;
9+
// In case of type error, check the type of 'make' in 'JSXV4.re' and './hookExample'.
10+
export const makeTypeChecked: <a>(_1:props<JSX.Element,person,JSX.Element,renderMe<a>>) => JSX.Element = makeNotChecked;
1111

12-
// Export 'foo' early to allow circular import from the '.bs.js' file.
13-
export const foo: unknown = function (Argperson: any) {
14-
const result = fooTypeChecked({person:Argperson});
15-
return result
16-
} as (_1:{ readonly person: person }) => string;
12+
// Export 'make' early to allow circular import from the '.bs.js' file.
13+
export const make: unknown = makeTypeChecked as <a>(_1:props<JSX.Element,person,JSX.Element,renderMe<a>>) => JSX.Element;
1714

1815
// tslint:disable-next-line:no-var-requires
1916
const JSXV4BS = require('./JSXV4.bs');
@@ -28,6 +25,18 @@ export type CompV4_props<x,y> = {
2825
// tslint:disable-next-line:interface-over-type-literal
2926
export type person = { readonly name: string; readonly age: number };
3027

28+
// tslint:disable-next-line:interface-over-type-literal
29+
export type renderMe<a> = React.ComponentType<{ readonly randomString: string; readonly poly: a }>;
30+
31+
// tslint:disable-next-line:interface-over-type-literal
32+
export type props<actions,person,children,renderMe> = {
33+
readonly key?: string;
34+
readonly actions?: actions;
35+
readonly person: person;
36+
readonly children: children;
37+
readonly renderMe: renderMe
38+
};
39+
3140
export const CompV4_make: React.ComponentType<{ readonly x: string; readonly y: string }> = JSXV4BS.CompV4.make;
3241

3342
// tslint:disable-next-line:interface-over-type-literal

jscomp/gentype_tests/typescript-react-example/src/JSXV4.res

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ type person = {
1818
age: int,
1919
}
2020

21+
@genType type renderMe<'a> = React.component<{"randomString": string, "poly": 'a}>
22+
2123
@@jsxConfig({version: 4})
2224

23-
@genType.import("./hookExample") external foo4: (~person: person) => string = "foo"
25+
@genType.import("./hookExample") @react.component
26+
external make: (
27+
~actions: React.element=?,
28+
~person: person,
29+
~children: React.element,
30+
~renderMe: renderMe<'a>,
31+
) => React.element = "make"

0 commit comments

Comments
 (0)