Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ed95f5

Browse filesBrowse files
authored
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
1 parent 0d4edfd commit 0ed95f5
Copy full SHA for 0ed95f5

File tree

Expand file treeCollapse file tree

1 file changed

+18
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-1
lines changed

‎src/api/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 numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ const attrs = useAttrs()
223223
`<script setup>` can be used alongside normal `<script>`. A normal `<script>` may be needed in cases where you need to:
224224

225225
- 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).
227227
- Run side effects or create objects that should only execute once.
228228

229229
```vue
@@ -265,6 +265,23 @@ In addition, the awaited expression will be automatically compiled in a format t
265265

266266
## TypeScript-only Features
267267

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+
268285
### Type-only props/emit declarations
269286

270287
Props and emits can also be declared using pure-type syntax by passing a literal type argument to `defineProps` or `defineEmits`:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.