Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions docs/writing-stories/typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -69,32 +69,57 @@ Sometimes stories need to define args that aren’t included in the component's
{/* prettier-ignore-end */}

<IfRenderer renderer="vue">
## Vue specific tips

Vue has excellent support for TypeScript, and we have done our utmost to take advantage of that in the stories files. For example, consider the following strongly typed Vue 3 single file component (SFC):
## Vue specific tips

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Hyphenate “Vue-specific”.

Minor grammar polish for the heading.

✏️ Proposed fix
-## Vue specific tips
+## Vue-specific tips
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Vue specific tips
## Vue-specific tips
🧰 Tools
🪛 LanguageTool

[grammar] ~73-~73: Use a hyphen to join words.
Context: ...*/} ## Vue specific tips Vue has excellent support...

(QB_NEW_EN_HYPHEN)

🤖 Prompt for AI Agents
In `@docs/writing-stories/typescript.mdx` at line 73, Update the heading "## Vue
specific tips" in docs/writing-stories/typescript.mdx to use the hyphenated form
"Vue-specific" so it reads "## Vue-specific tips"; locate the heading text and
replace the non-hyphenated word to correct the grammar.


```html
<script setup lang="ts">
defineProps<{ count: number; disabled: boolean }>();
Vue has excellent support for TypeScript, and we have done our utmost to take advantage of that in the stories files. For example, consider the following strongly typed Vue 3 single file component (SFC):

const emit = defineEmits<{
(e: 'increaseBy', amount: number): void;
(e: 'decreaseBy', amount: number): void;
}>();
</script>
```html
<script setup lang="ts">
defineProps<{ count: number; disabled: boolean }>();

<template>
<div class="card">
{{ count }}
<button @click="emit('increaseBy', 1)" :disabled="disabled">Increase by 1</button>
<button @click="$emit('decreaseBy', 1)" :disabled="disabled">Decrease by 1</button>
</div>
</template>
```
const emit = defineEmits<{
(e: 'increaseBy', amount: number): void;
(e: 'decreaseBy', amount: number): void;
}>();
</script>

<template>
<div class="card">
{{ count }}
<button @click="emit('increaseBy', 1)" :disabled="disabled">Increase by 1</button>
<button @click="$emit('decreaseBy', 1)" :disabled="disabled">Decrease by 1</button>
</div>
</template>
```

You can type check SFC files with `vue-tsc` and get editor support in VSCode by installing the official [Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar).

This setup will add type support for `*.vue` imports to your `*.stories.ts` files, providing the same type safety and autocomplete features.

[CSF Next](../api/csf/csf-next.mdx) adds support for [Generic Vue components](https://vuejs.org/api/sfc-script-setup.html#generics) (using `<script lang="ts" setup generic="T">`). Simply pass the type parameter directly to the component:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why GitHub is showing 18 changed files instead of just this one. I merged next into this branch, but that shouldn't bork the changes view like this. 🤷‍♂️

In any case, I moved your CSF Next FAQ entry to the Writing stories with TypeScript guide, because it only pertains to TypeScript users.


```ts title="GenericList.stories.ts"
import preview from '../.storybook/preview';

import GenericList from './GenericList.vue';

const meta = preview.meta({
// 👇 Pass the type parameter directly
component: GenericList<{ id: number; name: string }>,
});

export const Example = meta.story({
args: {
items: [{ id: 1, name: 'John Doe' }],
// 👇 item is correctly typed as { id: number; name: string }
getLabel: (item) => item.name,
},
});
```

You can type check SFC files with vue-tsc and get editor support in VSCode by installing the official [Vue](https://marketplace.visualstudio.com/items?itemName=Vue.volar) extension.
Prior CSF versions suffer from a [long-standing type inference issue](https://github.com/storybookjs/storybook/issues/24238) where the generic type `T` would default to `unknown`.

This setup will add type support for `*.vue` imports to your `*.stories.ts` files, providing the same type safety and autocomplete features.
</IfRenderer>

<IfRenderer renderer="svelte">
Expand Down