Skip to content

Commit f2dfb4e

Browse files
committed
Add examples of what can and cannot be used in bindings to functions.
1 parent d9359b8 commit f2dfb4e

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

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

Lines changed: 12 additions & 1 deletion
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/Core.gen.tsx

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

44

5+
import {someFunWithNullThenOptionalArgs as someFunWithNullThenOptionalArgsNotChecked} from './CoreTS';
6+
7+
import {someFunWithNullUndefinedArg as someFunWithNullUndefinedArgNotChecked} from './CoreTS';
8+
59
const $$toJS552311971: { [key: string]: any } = {"0": "A"};
610

711
const $$toRE552311971: { [key: string]: any } = {"A": 0};
812

9-
// @ts-ignore: Implicit any on import
10-
import * as CoreBS__Es6Import from './Core.bs';
11-
const CoreBS: any = CoreBS__Es6Import;
13+
// In case of type error, check the type of 'someFunWithNullThenOptionalArgs' in 'Core.res' and './CoreTS'.
14+
export const someFunWithNullThenOptionalArgsTypeChecked: (_1:(null | string), _2:(undefined | string)) => string = someFunWithNullThenOptionalArgsNotChecked;
15+
16+
// Export 'someFunWithNullThenOptionalArgs' early to allow circular import from the '.bs.js' file.
17+
export const someFunWithNullThenOptionalArgs: unknown = someFunWithNullThenOptionalArgsTypeChecked as (_1:(null | string), _2:(undefined | string)) => string;
18+
19+
// In case of type error, check the type of 'someFunWithNullUndefinedArg' in 'Core.res' and './CoreTS'.
20+
export const someFunWithNullUndefinedArgTypeChecked: (_1:(null | undefined | string), _2:number) => string = someFunWithNullUndefinedArgNotChecked;
21+
22+
// Export 'someFunWithNullUndefinedArg' early to allow circular import from the '.bs.js' file.
23+
export const someFunWithNullUndefinedArg: unknown = someFunWithNullUndefinedArgTypeChecked as (_1:(null | undefined | string), _2:number) => string;
24+
25+
// tslint:disable-next-line:no-var-requires
26+
const CoreBS = require('./Core.bs');
1227

1328
// tslint:disable-next-line:interface-over-type-literal
1429
export type variant = "A" | { tag: "B"; value: string };

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,16 @@ let option1 = (x: option<variant>) => x
7373
type t1 = {x?: string}
7474

7575
@genType
76-
type t2 = {x: Js.undefined<string>}
76+
type t2 = {x: Js.undefined<string>}
77+
78+
@genType.import("./CoreTS")
79+
external someFunWithNullThenOptionalArgs: (
80+
Null.t<string> /* Cannot be Nullable.t or option */,
81+
option<string> /* Cannot be Null.t or Nullable.t */,
82+
) => string = "someFunWithNullThenOptionalArgs"
83+
84+
@genType.import("./CoreTS")
85+
external someFunWithNullUndefinedArg: (
86+
Nullable.t<string> /* Can also be Null.t or option as they are subtypes */,
87+
int,
88+
) => string = "someFunWithNullUndefinedArg"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export declare function someFunWithNullThenOptionalArgs(
2+
nullable: null | string,
3+
app?: string
4+
): string;
5+
6+
export declare function someFunWithNullUndefinedArg(
7+
nullUndefined: null | undefined | string,
8+
other: number
9+
): string;

0 commit comments

Comments
 (0)