Skip to content

Not all components are typed with record type props #842

@Bushuo

Description

@Bushuo

The problem

We can type component props explicitly via a type props and

external make: React.component<props> = "SomeComponent"

This pattern is already used by most of the components here.

It enables record type spreads which are useful when we want to copy all props for our own component and add additional ones.

module Modal = {
  type props = {
    ...ReactNative.Modal.props,
    className?: string,
  }

  // maybe there is a better way to do this. My usecase is nativewind and this works.
  let make: React.component<props> = Obj.magic(ReactNative.Modal.make)
}

Without the prop type ReactNative.Modal.make would expect a generic parameter for all labeled arguments of the function, which is hard to type and error prone.

Considered solution

adjust components like Modal.res to use this pattern to define their props.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions