You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add clarification about type exports in SFCs (#1483)
* add clarification about type exports in SFCs
Latest vue / volar / vue-tsc complains when exporting additional types from SFCs (even though it worked previously). It seems this may be the intended behaviour, but was a bit unclear in these docs, so this change specifically calls out exporting types.
* Update sfc-script-setup.md
Copy file name to clipboardExpand all lines: src/api/sfc-script-setup.md
+18-1Lines changed: 18 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -223,7 +223,7 @@ const attrs = useAttrs()
223
223
`<script setup>` can be used alongside normal `<script>`. A normal `<script>` may be needed in cases where you need to:
224
224
225
225
- Declare options that cannot be expressed in `<script setup>`, for example `inheritAttrs` or custom options enabled via plugins.
226
-
- Declaring named exports.
226
+
- Declaring named exports (including TypeScript types).
227
227
- Run side effects or create objects that should only execute once.
228
228
229
229
```vue
@@ -265,6 +265,23 @@ In addition, the awaited expression will be automatically compiled in a format t
265
265
266
266
## TypeScript-only Features
267
267
268
+
### Additional type exports
269
+
270
+
As noted above, in order to export additional types from an SFC, they must be moved to an additional `<script>` block alongside the `<script setup>` block.
271
+
272
+
For example
273
+
```vue
274
+
<script lang="ts">
275
+
export type SizeOptions = 'small' | 'medium' | 'large';
276
+
</script>
277
+
278
+
<script lang="ts" setup>
279
+
defineProps({
280
+
size: { type: String as PropType<SizeOptions> },
281
+
})
282
+
</script>
283
+
```
284
+
268
285
### Type-only props/emit declarations
269
286
270
287
Props and emits can also be declared using pure-type syntax by passing a literal type argument to `defineProps` or `defineEmits`:
0 commit comments