storybook: [addon-knobs] Issue with select `options` type, does not support array of objects

Bug or support request summary

The select knob’s type is incorrect, as it does not support using an array of option objects, as per the example in the readme file.

const label = 'Dogs';
const arrayOfObjects = [
  {
    label: 'Sparky',
    dogParent: 'Matthew',
    location: 'Austin',
  },
  {
    label: 'Juniper',
    dogParent: 'Joshua',
    location: 'Austin',
  },
];
const defaultValue = arrayOfObjects[0];
const groupId = 'GROUP-ID3';
const value = select(label, options, defaultValue, groupId);

Side note: the example needs to be fixed options needs to be changed to arrayOfObjects.

Typescript complains with the following error:

Argument of type '{ label: string; dogParent: string; location: string; }[]' is not assignable to parameter of type 'SelectTypeOptionsProp<SelectTypeKnobValue>'.
  Type '{ label: string; dogParent: string; location: string; }[]' is not assignable to type 'ReactText[]'.
    Type '{ label: string; dogParent: string; location: string; }' is not assignable to type 'ReactText'.
      Type '{ label: string; dogParent: string; location: string; }' is not assignable to type 'number'.ts(2345)

Steps to reproduce

Try the above example.

Please specify which version of Storybook and optionally any affected addons that you’re running

Affected platforms

  • VSCode with Typescript v3.7.3

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 10
  • Comments: 20 (6 by maintainers)

Most upvoted comments

This is still an issue, can we keep it open?

@piemasters yeah, I understand the confusion. I posted that notice to all open addon-knobs issues regardless of whether controls solves the problem, and will continue to do so. I want everybody who uses knobs to knob about controls and upgrade as soon as it’s convenient. The sooner people upgrade, the sooner we can deprecate knobs, which doesn’t have any maintainers.