Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Fix props type constraint for shared props #705

Merged
merged 1 commit into from
Oct 27, 2022
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
15 changes: 12 additions & 3 deletions cli/reactjs_jsx_v4.ml
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,10 @@ let transformStructureItem ~config mapper item =
(Location.mkloc (Lident "props") pstr_loc)
(match coreTypeOfAttr with
| None -> makePropsTypeParams namedTypeList
| Some _ -> typVarsOfCoreType)
| Some _ -> (
match typVarsOfCoreType with
| [] -> []
| _ -> [Typ.any ()]))
in
(* type props<'x, 'y> = { x: 'x, y?: 'y, ... } *)
let propsRecordType =
Expand Down Expand Up @@ -1149,7 +1152,10 @@ let transformStructureItem ~config mapper item =
makePropsTypeParams ~stripExplicitOption:true
~stripExplicitJsNullableOfRef:hasForwardRef
namedTypeList
| Some _ -> typVarsOfCoreType)))
| Some _ -> (
match typVarsOfCoreType with
| [] -> []
| _ -> [Typ.any ()]))))
expression
in
(* let make = ({id, name, ...}: props<'id, 'name, ...>) => { ... } *)
Expand Down Expand Up @@ -1255,7 +1261,10 @@ let transformSignatureItem ~config _mapper item =
(Location.mkloc (Lident "props") psig_loc)
(match coreTypeOfAttr with
| None -> makePropsTypeParams namedTypeList
| Some _ -> typVarsOfCoreType)
| Some _ -> (
match typVarsOfCoreType with
| [] -> []
| _ -> [Typ.any ()]))
in
let propsRecordType =
makePropsRecordTypeSig ~coreTypeOfAttr ~typVarsOfCoreType "props"
Expand Down
16 changes: 8 additions & 8 deletions tests/ppx/react/expected/sharedProps.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module V4C1 = {
module V4C2 = {
type props<'a> = sharedProps<'a>

@react.component(: sharedProps<'a>) let make = ({x, y, _}: props<'a>) => React.string(x ++ y)
@react.component(: sharedProps<'a>) let make = ({x, y, _}: props<_>) => React.string(x ++ y)
let make = {
let \"SharedProps$V4C2" = (props: props<_>) => make(props)

Expand All @@ -26,7 +26,7 @@ module V4C3 = {
type props<'a> = sharedProps<string, 'a>

@react.component(: sharedProps<string, 'a>)
let make = ({x, y, _}: props<'a>) => React.string(x ++ y)
let make = ({x, y, _}: props<_>) => React.string(x ++ y)
let make = {
let \"SharedProps$V4C3" = (props: props<_>) => make(props)

Expand Down Expand Up @@ -54,13 +54,13 @@ module V4C5 = {
module V4C6 = {
type props<'a> = sharedProps<'a>

external make: React.componentLike<props<'a>, React.element> = "default"
external make: React.componentLike<props<_>, React.element> = "default"
}

module V4C7 = {
type props<'a> = sharedProps<string, 'a>

external make: React.componentLike<props<'a>, React.element> = "default"
external make: React.componentLike<props<_>, React.element> = "default"
}

module V4C8 = {
Expand All @@ -85,7 +85,7 @@ module V4A1 = {
module V4A2 = {
type props<'a> = sharedProps<'a>

@react.component(: sharedProps<'a>) let make = ({x, y, _}: props<'a>) => React.string(x ++ y)
@react.component(: sharedProps<'a>) let make = ({x, y, _}: props<_>) => React.string(x ++ y)
let make = {
let \"SharedProps$V4A2" = (props: props<_>) => make(props)

Expand All @@ -97,7 +97,7 @@ module V4A3 = {
type props<'a> = sharedProps<string, 'a>

@react.component(: sharedProps<string, 'a>)
let make = ({x, y, _}: props<'a>) => React.string(x ++ y)
let make = ({x, y, _}: props<_>) => React.string(x ++ y)
let make = {
let \"SharedProps$V4A3" = (props: props<_>) => make(props)

Expand Down Expand Up @@ -125,13 +125,13 @@ module V4A5 = {
module V4A6 = {
type props<'a> = sharedProps<'a>

external make: React.componentLike<props<'a>, React.element> = "default"
external make: React.componentLike<props<_>, React.element> = "default"
}

module V4A7 = {
type props<'a> = sharedProps<string, 'a>

external make: React.componentLike<props<'a>, React.element> = "default"
external make: React.componentLike<props<_>, React.element> = "default"
}

module V4A8 = {
Expand Down
8 changes: 4 additions & 4 deletions tests/ppx/react/expected/sharedProps.resi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ module V4C1: {
module V4C2: {
type props<'a> = sharedProps<'a>

let make: React.componentLike<props<'a>, React.element>
let make: React.componentLike<props<_>, React.element>
}

module V4C3: {
type props<'a> = sharedProps<string, 'a>

let make: React.componentLike<props<'a>, React.element>
let make: React.componentLike<props<_>, React.element>
}

module V4C4: {
Expand All @@ -35,13 +35,13 @@ module V4A1: {
module V4A2: {
type props<'a> = sharedProps<'a>

let make: React.componentLike<props<'a>, React.element>
let make: React.componentLike<props<_>, React.element>
}

module V4A3: {
type props<'a> = sharedProps<string, 'a>

let make: React.componentLike<props<'a>, React.element>
let make: React.componentLike<props<_>, React.element>
}

module V4A4: {
Expand Down