Skip to content

Commit 3004c1c

Browse files
committed
feat: added snippets for defineEmits, defineProps, withDefaults macros
Adds TypeScript snippets for Vue 3 Composition API macros: - v3emits-ts: defineEmits with TypeScript interface - v3props-ts: defineProps with TypeScript interface - v3withdefaults-ts: withDefaults with TypeScript interface Based on PR sdras#132 from mpchelnikov
1 parent 332fa7b commit 3004c1c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ These snippets are meant to provide a base scaffold for your single file compone
125125
| `v3watch-array` | Vue Composition API - watch as array |
126126
| `v3watcheffect` | Vue Composition API - watchEffect |
127127
| `v3ref` | Vue Ref |
128+
| `v3emits-ts` | Vue Composition API - defineEmits macros with TS |
129+
| `v3props-ts` | Vue Composition API - defineProps macros with TS |
130+
| `v3withdefaults-ts` | Vue Composition API - withDefaults macros with TS |
128131
| `v3onmounted` | Lifecycle hook - onMounted |
129132
| `v3onbeforemount` | Lifecycle hook - onBeforeMount |
130133
| `v3onbeforeupdate` | Lifecycle hook - onBeforeUpdate |

snippets/vue-script.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,41 @@
338338
"body": ["const ${1:name} = ref(${2:initialValue})"],
339339
"description": "Vue Ref"
340340
},
341+
"Vue Composition API - defineEmits": {
342+
"prefix": "v3emits-ts",
343+
"body": [
344+
"interface IEmits {",
345+
"\t(e: '${1:name}'): ${2},",
346+
"}",
347+
"",
348+
"const emit = defineEmits<IEmits>()"
349+
],
350+
"description": "Vue Composition api - defineEmits with Typescript"
351+
},
352+
"Vue Composition API - defineProps": {
353+
"prefix": "v3props-ts",
354+
"body": [
355+
"interface IProps {",
356+
"\t${1:name}: ${2},",
357+
"}",
358+
"",
359+
"const prop = defineProps<IProps>()"
360+
],
361+
"description": "Vue Composition api - defineProps with Typescript"
362+
},
363+
"Vue Composition API - withDefaults": {
364+
"prefix": "v3withdefaults-ts",
365+
"body": [
366+
"interface IProps {",
367+
"\t${1:name}: ${2},",
368+
"}",
369+
"",
370+
"const props = withDefaults(defineProps<IProps>(), {",
371+
"\t${1:name}: ${3},",
372+
"})"
373+
],
374+
"description": "Vue Composition api - withDefaults props with Typescript"
375+
},
341376
"Vue Lifecycle Hooks - onMounted": {
342377
"prefix": "v3onmounted",
343378
"body": ["onMounted(() => {${1}})"],

0 commit comments

Comments
 (0)