Skip to content

Commit 74834df

Browse files
authored
chore: fix type errors and add typecheck (#122)
1 parent 84592ed commit 74834df

File tree

6 files changed

+54
-26
lines changed

6 files changed

+54
-26
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ jobs:
8686
- name: Test
8787
run: pnpm run coverage
8888

89+
- name: Typecheck
90+
run: pnpm run typecheck
91+
8992
- name: Typecheck example
9093
run: pnpm run --filter {example} typecheck
9194

src/components/tables/DataTable.spec.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ import { describe, expect, it } from 'vitest';
22
import { type ComponentMountingOptions, mount } from '@vue/test-utils';
33
import DataTable, { type TableColumn } from '@/components/tables/DataTable.vue';
44

5-
const createWrapper = (options?: ComponentMountingOptions<typeof DataTable>) =>
6-
mount(DataTable, options);
5+
type User = {
6+
id: number;
7+
name: string;
8+
title: string;
9+
email: string;
10+
};
11+
12+
const createWrapper = (
13+
options?: ComponentMountingOptions<typeof DataTable<User>>,
14+
) => mount(DataTable<User>, options);
715

816
describe('DataTable', () => {
9-
const data = [
17+
const data: User[] = [
1018
...[...new Array(50)].map((_, index) => ({
1119
id: index + 1,
1220
name: `Lindsay Walton ${index}`,
@@ -15,7 +23,7 @@ describe('DataTable', () => {
1523
})),
1624
];
1725

18-
const columns: TableColumn[] = [
26+
const columns: TableColumn<User>[] = [
1927
{
2028
key: 'id',
2129
label: 'ID',

src/components/tables/DataTable.stories.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
import Button from '@/components/buttons/button/Button.vue';
22
import TextField from '@/components/forms/text-field/TextField.vue';
33
import Icon from '@/components/icons/Icon.vue';
4-
import DataTable, { type Props, type TableColumn } from './DataTable.vue';
4+
import DataTable, {
5+
type TableColumn,
6+
type Props as TableProps,
7+
} from './DataTable.vue';
58
import type { Meta, StoryFn, StoryObj } from '@storybook/vue3';
69

10+
type User = {
11+
id: number;
12+
name: string;
13+
title: string;
14+
email: string;
15+
role: string;
16+
date: string;
17+
};
18+
19+
type Props = TableProps<User, 'id'>;
20+
721
const render: StoryFn<Props> = (args) => ({
8-
components: { DataTable, Button, Icon, TextField },
22+
components: { DataTable: DataTable<User>, Button, Icon, TextField },
923
setup() {
1024
const modelValue = computed({
1125
get() {
@@ -139,7 +153,7 @@ const data = [
139153
})),
140154
];
141155

142-
const columns: TableColumn[] = [
156+
const columns: TableColumn<User>[] = [
143157
{
144158
key: 'id',
145159
label: 'ID',
@@ -172,7 +186,7 @@ const columns: TableColumn[] = [
172186

173187
const meta: Meta<Props> = {
174188
title: 'Components/Tables/DataTable',
175-
component: DataTable,
189+
component: DataTable as any,
176190
tags: ['autodocs'],
177191
render,
178192
argTypes: {
@@ -203,8 +217,8 @@ const meta: Meta<Props> = {
203217
'tfoot',
204218
'no-data',
205219
'empty-description',
206-
'`header.${column.key}`',
207-
'`item.${column.key}`',
220+
'`header.${column.key.toString()}`',
221+
'`item.${column.key.toString()}`',
208222
],
209223
},
210224
},

src/components/tabs/tab-items/TabItems.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@ vi.mock('@headlessui/vue', () => ({
1616
const createWrapper = (options?: ComponentMountingOptions<typeof TabItems>) =>
1717
mount(TabItems, {
1818
...options,
19+
global: { stubs: { TabItem } },
1920
slots: {
2021
default: [
21-
h(TabItem, [h('div', 'Tab Content 1')]),
22-
h(TabItem, [h('div', 'Tab Content 2')]),
23-
h(TabItem, [h('div', 'Tab Content 3')]),
24-
h(TabItem, [h('div', 'Tab Content 4')]),
22+
{ template: '<TabItem><div>Tab Content 1</div></TabItem>' },
23+
{ template: '<TabItem><div>Tab Content 2</div></TabItem>' },
24+
{ template: '<TabItem><div>Tab Content 3</div></TabItem>' },
25+
{ template: '<TabItem><div>Tab Content 4</div></TabItem>' },
2526
],
2627
},
2728
});
2829

2930
describe('Tabs/TabItems', () => {
3031
it('renders properly', async () => {
31-
const modelValue = ref(0);
3232
const wrapper = createWrapper({
3333
props: {
34-
modelValue,
34+
modelValue: 0,
3535
},
3636
});
3737

3838
await nextTick();
3939
await nextTick();
4040
expect(wrapper.text()).toBe('Tab Content 1');
4141

42-
set(modelValue, 1);
43-
await nextTick();
42+
await wrapper.setProps({ modelValue: 1 });
4443
await nextTick();
4544
await nextTick();
45+
4646
expect(wrapper.text()).toBe('Tab Content 2');
4747
});
4848
});

src/components/tabs/tabs/Tabs.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ const createWrapper = (options?: ComponentMountingOptions<typeof Tabs>) =>
1313
global: {
1414
stubs: {
1515
RouterLink: RouterLinkStub,
16+
Tab,
1617
},
1718
},
1819
slots: {
1920
default: [
20-
h(Tab, [h('div', 'Tab 1')]),
21-
h(Tab, [h('div', 'Tab 2')]),
22-
h(Tab, [h('div', 'Tab 3')]),
23-
h(Tab, [h('div', 'Tab 4')]),
21+
{ template: '<Tab><div>Tab 1</div></Tab>' },
22+
{ template: '<Tab><div>Tab 2</div></Tab>' },
23+
{ template: '<Tab><div>Tab 3</div></Tab>' },
24+
{ template: '<Tab><div>Tab 4</div></Tab>' },
2425
],
2526
},
2627
});
@@ -30,7 +31,7 @@ describe('Tabs/Tabs', () => {
3031
const modelValue = ref();
3132
const wrapper = createWrapper({
3233
props: {
33-
modelValue,
34+
modelValue: get(modelValue),
3435
'onUpdate:modelValue': (e: any) => set(modelValue, e),
3536
},
3637
});
@@ -105,7 +106,7 @@ describe('Tabs/Tabs', () => {
105106
const modelValue = ref();
106107
const wrapper = createWrapper({
107108
props: {
108-
modelValue,
109+
modelValue: get(modelValue),
109110
'onUpdate:modelValue': (e: any) => set(modelValue, e),
110111
},
111112
});

src/components/tabs/tabs/Tabs.stories.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import Card from '@/components/cards/Card.vue';
55
import Tab from '@/components/tabs/tab/Tab.vue';
66
import TabItems from '@/components/tabs/tab-items/TabItems.vue';
77
import TabItem from '@/components/tabs/tab-item/TabItem.vue';
8-
import Tabs, { type Props } from './Tabs.vue';
8+
import Tabs, { type Props as TabsProps } from './Tabs.vue';
9+
10+
type Props = TabsProps & { class?: string };
911

1012
const render: StoryFn<Props> = (args) => ({
1113
components: { Tabs, Tab, TabItems, TabItem, Card, Icon },
@@ -124,7 +126,7 @@ export const DefaultWithArrow: Story = {
124126
export const VerticalWithArrow: Story = {
125127
args: {
126128
vertical: true,
127-
className: 'w-[200px] h-[300px]',
129+
class: 'w-[200px] h-[300px]',
128130
},
129131
};
130132

0 commit comments

Comments
 (0)