Proptype error when using Requireable<NonNullable<string...>

25 views Asked by At
Type 'Requireable<NonNullable<string | ((...args: any[]) => any) | null | undefined>>' is not assignable to type 'Validator<"auto" | "above" | "below" | "auto left" | "auto center" | "auto right" | "above left" | "above center" | "above right" | "below left" | "below center" | "below right" | ((self: Instance, customElement: HTMLElement | undefined) => void) | null | undefined>'.   Types of property '[nominalTypeHack]' are incompatible.
    Type '{ type: NonNullable<string | ((...args: any[]) => any) | null | undefined> | null | undefined; } | undefined' is not assignable to type '{ type: "auto" | "above" | "below" | "auto left" | "auto center" | "auto right" | "above left" | "above center" | "above right" | "below left" | "below center" | "below right" | ((self: Instance, customElement: HTMLElement | undefined) => void) | null | undefined; } | undefined'.
      Type '{ type: NonNullable<string | ((...args: any[]) => any) | null | undefined> | null | undefined; }' is not assignable to type '{ type: "auto" | "above" | "below" | "auto left" | "auto center" | "auto right" | "above left" | "above center" | "above right" | "below left" | "below center" | "below right" | ((self: Instance, customElement: HTMLElement | undefined) => void) | null | undefined; }'.
        Types of property 'type' are incompatible.
          Type 'NonNullable<string | ((...args: any[]) => any) | null | undefined> | null | undefined' is not assignable to type '"auto" | "above" | "below" | "auto left" | "auto center" | "auto right" | "above left" | "above center" | "above right" | "below left" | "below center" | "below right" | ((self: Instance, customElement: HTMLElement | undefined) => void) | null | undefined'.
            Type 'string' is not assignable to type '"auto" | "above" | "below" | "auto left" | "auto center" | "auto right" | "above left" | "above center" | "above right" | "below left" | "below center" | "below right" | ((self: Instance, customElement: HTMLElement | undefined) => void) | null | undefined'.ts(2322)

I get this error when I am setting this propType:

   position: PropTypes.oneOfType([
      PropTypes.oneOf([
        'auto',
        'above',
        'below',
        'auto left',
        'auto center',
        'auto right',
        'above left',
        'above center',
        'above right',
        'below left',
        'below center',
        'below right',
      ]),
      PropTypes.func,
    ]) 

The solution was to add:

as PropTypes.Requireable<"auto" | "above" | "below" | "auto left" | "auto center" | "auto right" | "above left" | "above center" | "above right" | "below left" | "below center" | "below right" | ((self: Instance, customElement: HTMLElement | undefined) => void) | null | undefined>,

Is there a more elegant solution, it seems crazy to me that I need to add all of these things when I am trying to add an optional proptype.

0

There are 0 answers