Skip to content

GenType: fix issue with V3 compatibility mode #5991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ These are only breaking changes for unformatted code.
- Fix support for recursive components in JSX V4 https://github.com/rescript-lang/rescript-compiler/pull/5986
- Fix issue with overlapping labelled argument with default value https://github.com/rescript-lang/rescript-compiler/pull/5989
- Fix issue with using alias and default value together https://github.com/rescript-lang/rescript-compiler/pull/5989
- GenType: fix issue with V3 compatibility mode (see https://github.com/rescript-lang/rescript-compiler/issues/5990) https://github.com/rescript-lang/rescript-compiler/pull/5991

#### :nail_care: Polish

Expand Down
23 changes: 17 additions & 6 deletions jscomp/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
paramTranslation1.dependencies @ paramTranslation2.dependencies;
type_ = variant;
}
| ["React"; "callback"], [fromTranslation; toTranslation] ->
| ( (["React"; "callback"] | ["ReactV3"; "React"; "callback"]),
[fromTranslation; toTranslation] ) ->
{
dependencies = fromTranslation.dependencies @ toTranslation.dependencies;
type_ =
Expand All @@ -140,7 +141,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
uncurried = false;
};
}
| ["React"; "componentLike"], [propsTranslation; retTranslation] ->
| ( (["React"; "componentLike"] | ["ReactV3"; "React"; "componentLike"]),
[propsTranslation; retTranslation] ) ->
{
dependencies = propsTranslation.dependencies @ retTranslation.dependencies;
type_ =
Expand All @@ -153,7 +155,8 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
uncurried = false;
};
}
| ["React"; "component"], [propsTranslation] ->
| ( (["React"; "component"] | ["ReactV3"; "React"; "component"]),
[propsTranslation] ) ->
{
dependencies = propsTranslation.dependencies;
type_ =
Expand All @@ -166,12 +169,17 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
uncurried = false;
};
}
| ["React"; "Context"; "t"], [paramTranslation] ->
| ( (["React"; "Context"; "t"] | ["ReactV3"; "React"; "Context"; "t"]),
[paramTranslation] ) ->
{
dependencies = paramTranslation.dependencies;
type_ = EmitType.typeReactContext ~type_:paramTranslation.type_;
}
| (["React"; "Ref"; "t"] | ["React"; "ref"]), [paramTranslation] ->
| ( ( ["React"; "Ref"; "t"]
| ["React"; "ref"]
| ["ReactV3"; "React"; "Ref"; "t"]
| ["ReactV3"; "React"; "ref"] ),
[paramTranslation] ) ->
{
dependencies = paramTranslation.dependencies;
type_ = EmitType.typeReactRef ~type_:paramTranslation.type_;
Expand All @@ -186,7 +194,10 @@ let translateConstr ~config ~paramsTranslation ~(path : Path.t) ~typeEnv =
{dependencies = []; type_ = EmitType.typeAny}
| ["ReactEvent"; "Mouse"; "t"], [] ->
{dependencies = []; type_ = EmitType.typeReactEventMouseT}
| (["React"; "element"] | ["ReasonReact"; "reactElement"]), [] ->
| ( ( ["React"; "element"]
| ["ReactV3"; "React"; "element"]
| ["ReasonReact"; "reactElement"] ),
[] ) ->
{dependencies = []; type_ = EmitType.typeReactElement}
| (["FB"; "option"] | ["option"]), [paramTranslation] ->
{paramTranslation with type_ = Option paramTranslation.type_}
Expand Down
131 changes: 38 additions & 93 deletions jscomp/gentype_tests/typescript-react-example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions jscomp/gentype_tests/typescript-react-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1"
"@rescript/react": "^0.11.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"scripts": {
"start": "rescript build -w",
Expand All @@ -13,7 +14,6 @@
"tsc": "tsc -p tsconfig.json"
},
"devDependencies": {
"@rescript/react": "^0.10.3",
"@types/node": "^13.13.4",
"@types/react-dom": "^16.9.7",
"rescript": "file:../../..",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* TypeScript file generated from V3Compatibility.res by genType. */
/* eslint-disable import/first */


// tslint:disable-next-line:interface-over-type-literal
export type cb = (_1:number) => string;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open ReactV3

@genType
type cb = React.callback<int, string>