Skip to content
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

feat: strict types for form events #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion src/ReactEvent.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,31 @@ module MakeEventWithType = (
@send external persist: Type.t => unit = "persist"
}

module MakeEventWithTypeStrict = (
Type: {
type t
},
) => {
@get external bubbles: Type.t => bool = "bubbles"
@get external cancelable: Type.t => bool = "cancelable"
@get
external currentTarget: Type.t => Js.Json.t = "currentTarget" /* Should return Dom.eventTarget */
@get external defaultPrevented: Type.t => bool = "defaultPrevented"
@get external eventPhase: Type.t => int = "eventPhase"
@get external isTrusted: Type.t => bool = "isTrusted"
@get external nativeEvent: Type.t => Js.Json.t = "nativeEvent" /* Should return Dom.event */
@send external preventDefault: Type.t => unit = "preventDefault"
@send
external isDefaultPrevented: Type.t => bool = "isDefaultPrevented"
@send external stopPropagation: Type.t => unit = "stopPropagation"
@send
external isPropagationStopped: Type.t => bool = "isPropagationStopped"
@get external target: Type.t => Js.Json.t = "target" /* Should return Dom.eventTarget */
@get external timeStamp: Type.t => float = "timeStamp"
@get external type_: Type.t => string = "type"
@send external persist: Type.t => unit = "persist"
}

module Synthetic = {
type tag = JsxEvent.Synthetic.tag
type t = synthetic<tag>
Expand Down Expand Up @@ -109,7 +134,7 @@ module Focus = {
module Form = {
type tag = JsxEvent.Form.tag
type t = synthetic<tag>
include MakeEventWithType({
include MakeEventWithTypeStrict({
type t = t
})
}
Expand Down
6 changes: 3 additions & 3 deletions src/ReactEvent.resi
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ module Form: {
type t = synthetic<tag>
@get external bubbles: t => bool = "bubbles"
@get external cancelable: t => bool = "cancelable"
@get external currentTarget: t => {..} = "currentTarget"
@get external currentTarget: t => Js.Json.t = "currentTarget"
@get external defaultPrevented: t => bool = "defaultPrevented"
@get external eventPhase: t => int = "eventPhase"
@get external isTrusted: t => bool = "isTrusted"
@get external nativeEvent: t => {..} = "nativeEvent"
@get external nativeEvent: t => Js.Json.t = "nativeEvent"
@send external preventDefault: t => unit = "preventDefault"
@send external isDefaultPrevented: t => bool = "isDefaultPrevented"
@send external stopPropagation: t => unit = "stopPropagation"
@send external isPropagationStopped: t => bool = "isPropagationStopped"
@get external target: t => {..} = "target"
@get external target: t => Js.Json.t = "target"
@get external timeStamp: t => float = "timeStamp"
@get external type_: t => string = "type"
@send external persist: t => unit = "persist"
Expand Down