Skip to content

Allow function type in untagged variants #6278

Closed
@fhammerschmidt

Description

@fhammerschmidt

Just tried to bind the MUI SxProps with untagged variants.

This is the TS definition:

export type SxProps<Theme extends object = {}> =
  | SystemStyleObject<Theme>
  | ((theme: Theme) => SystemStyleObject<Theme>)
  | ReadonlyArray<
      boolean | SystemStyleObject<Theme> | ((theme: Theme) => SystemStyleObject<Theme>)
    >;

and this is my attempt in ReScript:

module SxProps = {
  type theme = {primaryColor?: string}
  type systemStyleObject = {mr?: int, color?: string}

  @unboxed
  type rec t =
    | @as(false) False
    | @as(true) True
    | Object(systemStyleObject)
    | Array(array<t>)
    | Callback(callback)
  and callback = theme => systemStyleObject
}

which, aside from the fact that it's simplified because the array should not be nested and the booleans should only be nested, does not work, because one cannot use a function (the Callback variant in this example) type here.

Would it be possible to add that? Since you can check that easily with typeof == "function".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions