question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript errors when using template.bind() with Story type

See original GitHub issue

Describe the bug

New typings in this commit cause typescript errors when using bind() as Story can now be a function or an object

https://github.com/storybookjs/storybook/commit/70888b3747c6d1d270f53a44183df389a029a1e7#diff-c1c2ef0d3d6300dc7fbb01f6c686034508ebdec1b5ebe6e657ba6a5f0b037f6c

TS2339: Property ‘bind’ does not exist on type ‘Story<any>’.   Property ‘bind’ does not exist on type ‘BaseStoryObject<any, StoryFnAngularReturnType> & Annotations<any, StoryFnAngularReturnType>’.

export declare type BaseStory<Args, StoryFnReturnType> = BaseStoryFn<Args, StoryFnReturnType> | BaseStoryObject<Args, StoryFnReturnType>;

When I remove the BaseStoryObject the error goes away

export declare type BaseStory<Args, StoryFnReturnType> = BaseStoryFn<Args, StoryFnReturnType>;

To Reproduce

My template is in a helper class like so.

class Utils {
    template: Story = () => ({});
}

let utils = new Utils();
utils.bar.bind({});

Issue screenshot Screenshot 2021-07-29 at 15 32 55

What is strange is that this only happens when my template is in a class, This code below does not have the error

const baz: Story = () => ({});
baz.bind({})

System

Angular 12.1.4

Environment Info:

System: OS: macOS 11.5 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Binaries: Node: 14.15.5 - ~/.nvm/versions/node/v14.15.5/bin/node Yarn: 1.22.10 - ~/.nvm/versions/node/v14.15.5/bin/yarn npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm Browsers: Chrome: 92.0.4515.107 Edge: 92.0.902.55 Firefox: 89.0.2 Safari: 14.1.2 npmPackages: @storybook/addon-a11y: ^6.4.0-alpha.22 => 6.4.0-alpha.22 @storybook/addon-actions: ^6.4.0-alpha.22 => 6.4.0-alpha.22 @storybook/addon-essentials: ^6.4.0-alpha.22 => 6.4.0-alpha.22 @storybook/addon-links: ^6.4.0-alpha.22 => 6.4.0-alpha.22 @storybook/angular: ^6.4.0-alpha.22 => 6.4.0-alpha.22 @storybook/builder-webpack5: ^6.4.0-alpha.22 => 6.4.0-alpha.22 @storybook/manager-webpack5: ^6.4.0-alpha.22 => 6.4.0-alpha.22

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
dexstercommented, Aug 3, 2021

Thanks for the update. I’ve taken a look at CSF3 and I’m happy to manually migrate. CSF3 gets rid of a lot of repetition that will probably remove the need for my utility class.

1reaction
shilmancommented, Jul 30, 2021

@yannbf can you please take a look at this one?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript typings for controls args · Issue #11916 - GitHub
It appears using Template.bind({}) results in type any . To have each story's args typechecked, you must manually specify the type.
Read more >
Type is not assignable to type | Learning type script and story ...
Solution 1: Use the Button props in your Button component decleration ... const Template: Story<ActualButtonProps> = (args) => <Button ...
Read more >
Writing stories in TypeScript - Storybook - JS.ORG
In this snippet, the Primary and Secondary stories are cloning the Template function. By enabling the strictBindCallApply TypeScript option, ...
Read more >
The starting point for learning TypeScript
Find TypeScript starter projects: from Angular to React or Node.js and CLIs. ... Learn how to write declaration files to describe existing JavaScript....
Read more >
Data Binding in a Template - Salesforce Lightning Component ...
In the template, surround the property with curly braces, { property } . To compute a value for the property, use a JavaScript...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found