vue-component-type-helpers 3.2.3 → 3.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +112 -15
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,26 +1,123 @@
1
1
  # vue-component-type-helpers
2
2
 
3
- Some very simple type helpers used behind `vue-component-meta` for extract component props, slots, emit, exposed types.
3
+ <p>
4
+ <a href="https://www.npmjs.com/package/vue-component-type-helpers"><img src="https://img.shields.io/npm/v/vue-component-type-helpers.svg?labelColor=18181B&color=1584FC" alt="NPM version"></a>
5
+ <a href="https://github.com/vuejs/language-tools/blob/master/LICENSE"><img src="https://img.shields.io/github/license/vuejs/language-tools.svg?labelColor=18181B&color=1584FC" alt="License"></a>
6
+ </p>
4
7
 
5
- ## Usage
8
+ Helper utilities for extracting types such as props, slots, attrs, emit, and exposed from Vue component types. No runtime dependencies; provides TypeScript type definitions only.
6
9
 
7
- ```vue
8
- <template>
9
- <slot name="header" :num="123" />
10
- <slot name="footer" str="abc" />
11
- </template>
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install vue-component-type-helpers
14
+ ```
15
+
16
+ ## Type Helpers
17
+
18
+ ### `ComponentProps<T>`
19
+
20
+ Extracts the props type of a component.
21
+
22
+ ```typescript
23
+ import type { ComponentProps } from 'vue-component-type-helpers';
24
+ import MyComponent from './MyComponent.vue';
25
+
26
+ type Props = ComponentProps<typeof MyComponent>;
27
+ ```
28
+
29
+ ### `ComponentSlots<T>`
30
+
31
+ Extracts the slots type of a component.
32
+
33
+ ```typescript
34
+ import type { ComponentSlots } from 'vue-component-type-helpers';
35
+ import MyComponent from './MyComponent.vue';
36
+
37
+ type Slots = ComponentSlots<typeof MyComponent>;
38
+ ```
39
+
40
+ ### `ComponentAttrs<T>`
41
+
42
+ Extracts the attrs type of a component.
43
+
44
+ ```typescript
45
+ import type { ComponentAttrs } from 'vue-component-type-helpers';
46
+ import MyComponent from './MyComponent.vue';
47
+
48
+ type Attrs = ComponentAttrs<typeof MyComponent>;
49
+ ```
50
+
51
+ ### `ComponentEmit<T>`
52
+
53
+ Extracts the emit function type of a component.
12
54
 
13
- <script lang="ts" setup>
55
+ ```typescript
56
+ import type { ComponentEmit } from 'vue-component-type-helpers';
57
+ import MyComponent from './MyComponent.vue';
58
+
59
+ type Emit = ComponentEmit<typeof MyComponent>;
60
+ ```
61
+
62
+ ### `ComponentExposed<T>`
63
+
64
+ Extracts the instance type exposed via `defineExpose`.
65
+
66
+ ```typescript
67
+ import type { ComponentExposed } from 'vue-component-type-helpers';
68
+ import MyComponent from './MyComponent.vue';
69
+
70
+ type Exposed = ComponentExposed<typeof MyComponent>;
71
+ ```
72
+
73
+ ## Example
74
+
75
+ Given the following component:
76
+
77
+ ```vue
78
+ <!-- MyComponent.vue -->
79
+ <script setup lang="ts">
14
80
  defineProps<{
15
- msg: string
16
- }>()
81
+ title: string;
82
+ count?: number;
83
+ }>();
84
+
85
+ defineEmits<{
86
+ update: [value: string];
87
+ close: [];
88
+ }>();
89
+
90
+ defineSlots<{
91
+ default(props: { item: string }): any;
92
+ header(): any;
93
+ }>();
94
+
95
+ const internalState = ref(0);
96
+ defineExpose({
97
+ reset: () => { internalState.value = 0; },
98
+ });
17
99
  </script>
18
100
  ```
19
101
 
20
- ```ts
21
- import HelloWorld from './HelloWorld.vue'
22
- import type { ComponentProps, ComponentSlots } from 'vue-component-type-helpers'
102
+ Using type helpers:
103
+
104
+ ```typescript
105
+ import type { ComponentProps, ComponentSlots, ComponentEmit, ComponentExposed } from 'vue-component-type-helpers';
106
+ import MyComponent from './MyComponent.vue';
23
107
 
24
- type Props = ComponentProps<typeof HelloWorld> // { msg: string }
25
- type Slots = ComponentSlots<typeof HelloWorld> // { header?: (props: { num: number; }) => any; footer?: (props: { str: string; }) => any; }
108
+ type Props = ComponentProps<typeof MyComponent>;
109
+ // { title: string; count?: number }
110
+
111
+ type Slots = ComponentSlots<typeof MyComponent>;
112
+ // { default(props: { item: string }): any; header(): any }
113
+
114
+ type Emit = ComponentEmit<typeof MyComponent>;
115
+ // { (e: 'update', value: string): void; (e: 'close'): void }
116
+
117
+ type Exposed = ComponentExposed<typeof MyComponent>;
118
+ // { reset: () => void }
26
119
  ```
120
+
121
+ ## License
122
+
123
+ [MIT](https://github.com/vuejs/language-tools/blob/master/LICENSE) License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-component-type-helpers",
3
- "version": "3.2.3",
3
+ "version": "3.2.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -12,5 +12,5 @@
12
12
  "url": "https://github.com/vuejs/language-tools.git",
13
13
  "directory": "packages/component-type-helpers"
14
14
  },
15
- "gitHead": "efc6882ab62a518b41ab5c8dc1d762c41c862ebc"
15
+ "gitHead": "ee5041d27940cf6f9a5150635d3b13140a9dff54"
16
16
  }