Skip to content

Vue with TypeScript

Vue 3 + <script setup lang="ts"> offers excellent TypeScript ergonomics. This lesson covers practical patterns, syntax, and mistakes to avoid.

Typing Vue Apps

Vue 3 + <script setup lang="ts"> offers excellent TypeScript ergonomics.

Type props/emits and store state for safer refactors.

<script setup lang="ts">
const props = defineProps<{ title: string }>()
</script>

Type-based defineProps.

Tooling

vue-tsc, Volar/Vue - Official extension
  • Handle loading and errors.
  • Keep composables tested.
  • Prefer TypeScript when you can.
  • Measure before optimizing.

Vue with TypeScript Cheatsheet

Quick reference for patterns covered in this lesson.

Item Example Purpose
lang=ts SFC Enable
defineProps types Props
defineEmits types Events
pinia typed stores State
vue-tsc CLI check CI
strict tsconfig Quality

Takeover Mode

Use the official Vue TS extension setup recommended by docs.

Common Mistakes

  • any everywhere.
  • Skipping vue-tsc in CI.

Key Takeaways

  • Vue with TypeScript shows up often in Vue apps.
  • Practice with a demo.
  • Prefer clear APIs.
  • Read official docs for edge cases.

Pro Tip

Turn on strict mode early — migrating later is harder.