score:1

the problem is you're passing non-readonly array to the oneof validator. and the values of non-readonly array are inferred as string type. the solution is pretty simple. just pass it readonly tuple:

   ...
   type: proptypes.oneof(['dropdown', 'checkbox'] as const).isrequired,
   ...

updated answer to address the second error.

to match the type: data: array<plugindropdowndata> | array<string> you have to define your proptypes as:

   ...
   data: proptypes.oneoftype([
       proptypes.arrayof(proptypes.shape({
           label: proptypes.string.isrequired,
           value: proptypes.string.isrequired,
       }).isrequired),
       proptypes.arrayof(proptypes.string.isrequired),
   ]).isrequired,

notice that if you want the array to pass the validation you have to declare it's elements as isrequired. if you're not planning to make them isrequired you have to add | null | undefined to array's item type. for example those two definitions pass without error:

type pluginmanifestobject = {
   ...
   data: array<plugindropdowndata | undefined | null> | array<string | undefined | null>
   ...
}

   ...
   data: proptypes.oneoftype([
      proptypes.arrayof(proptypes.shape({
          label: proptypes.string.isrequired,
          value: proptypes.string.isrequired,
      })),
      proptypes.arrayof(proptypes.string),
  ]).isrequired,
  ...

Related Query

More Query from same tag