nx icon indicating copy to clipboard operation
nx copied to clipboard

Stories with typescript should type the variable directly instead of using `as` cast

Open Fuco1 opened this issue 3 years ago • 1 comments

Description

When using component-story generator with typescript, it uses "casting" (as) instead of typing the object directly. Some projects have eslint rules flagging casts as warnings or errors and then they need to disable warnings in nx generated files or rewrite them.

Motivation

Typecasting with as is not type-safe since the user must "be sure" they do the right thing and the compiler can't really help.

Suggested Implementation

Instead of

export default {
  component: Test,
  title: 'Test',  
} as ComponentMeta<typeof Test>;

use

const story: ComponentMeta<typeof Test> = {
  component: Test,
  title: 'Test',  
};

export default story;

Fuco1 avatar Sep 20 '22 15:09 Fuco1

Hi there @Fuco1 ! Thanks for the feature request! I see you're willing to implement this feature? Do you want to give this a shot, and reach out to me if you need any support in the process?

mandarini avatar Sep 21 '22 11:09 mandarini

@mandarini sure thing! Any legalese that needs to be handled?

As far as I see this should just amount to change of the template.

Fuco1 avatar Sep 23 '22 12:09 Fuco1

I think so too @Fuco1 ! Do you want to start working on it (fork nx, start a new branch, create a draft PR), and I can take a look and we can take it step by step? Thank you so much!!!

(see this guide for contributing)

mandarini avatar Sep 23 '22 15:09 mandarini

I took it up, no worries @Fuco1 !

mandarini avatar Sep 26 '22 14:09 mandarini

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

github-actions[bot] avatar Mar 21 '23 19:03 github-actions[bot]