質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

1回答

3462閲覧

typescript storybookの型が合わない

kakedashidesu

総合スコア50

TypeScript

TypeScriptは、マイクロソフトによって開発された フリーでオープンソースのプログラミング言語です。 TypeScriptは、JavaScriptの構文の拡張であるので、既存の JavaScriptのコードにわずかな修正を加えれば動作します。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2021/04/07 08:44

編集2021/04/07 09:23

const Template: Story = (args: IconButtonProps) => <IconButton {...args} />;のTemplateで下記のエラーが発生します。
iconのエラーだと思うのですがどこがおかしいのかがわかりません。
わかる人いましたらご教授お願いしたいです

typescriptエラー

Type '(args: IconButtonProps) => JSX.Element' is not assignable to type 'Story<Args>'. Type '(args: IconButtonProps) => JSX.Element' is not assignable to type 'BaseStory<Args, StoryFnReactReturnType>'. Types of parameters 'args' and 'args' are incompatible. Type 'Args' is not assignable to type 'IconButtonProps'. Property 'icon' is missing in type 'Args' but required in type '{ icon: IconTypes; }'.ts(2322) IconButton.tsx(9, 3): 'icon' is declared here.
import React, {FC} from 'react'; import { IconButton as ChakraButton, ButtonProps } from '@chakra-ui/react'; import { IconTypes } from '.././Icon/iconOption'; import { TwitterIcon } from '../Icon/TwitterIcon'; import { LinkedInIcon } from '../Icon/LinkedInIcon'; import { FacebookIcon } from '../Icon/FacebookIcon'; export type IconButtonProps = ButtonProps & { icon: IconTypes; }; type IconObject = { components: JSX.Element; label: string; }; ChakraButton.defaultProps = { size: 'md', }; export const IconButton: FC<IconButtonProps> = ({ icon, children, ...props }) => { const Icon: Record<IconTypes, IconObject> = { twitter: { components: <TwitterIcon />, label: 'twitter', }, linkedIn: { components: <LinkedInIcon />, label: 'linkedIn', }, facebook: { components: <FacebookIcon />, label: 'facebook', }, }; return ( <ChakraButton icon={Icon[icon].components} aria-label={Icon[icon].label} {...props} > {children} </ChakraButton> ); };
// IconButon.stories.tsx import React from 'react'; import { Story } from '@storybook/react/types-6-0'; import { IconButton, IconButtonProps } from './IconButton'; import { IconOpitions } from '.././Icon/iconOption'; export default { title: 'atoms/IconButton', component: IconButton, argTypes: { icon: { description: 'ボタンで使用するアイコンです', table: { type: { summary: 'string', required: true }, }, control: { type: 'inline-radio', options: IconOpitions, }, }, }, }; const Template: Story = (args: IconButtonProps) => <IconButton {...args} />; export const Icon = Template.bind({}); Icon.args = { icon: 'dots', };
// IconOption.ts export const IconOpitions = [ 'twitter', 'linkedIn', 'facebook', ]; export type IconTypes = 'twitter' | 'linkedIn' | 'facebook';

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

おそらくここだと思います。

ts

1const Template: Story = (args: IconButtonProps) => <IconButton {...args} />; 2// ↑を↓に 3const Template: Story<IconButtonProps> = (args) => <IconButton {...args} />;

蛇足ですが、TypeScriptでは変数に関数を代入する場合には、引数や返値の型を記述するのは避けられる傾向があって、変数宣言にだけ型を付けるパターンが多いです。

投稿2021/04/07 14:48

croutonn

総合スコア11

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kakedashidesu

2021/04/08 02:03

ありがとうございます!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問