Skip to content

Twoslash Vue

This package added the support for Twoslash to handle Vue Single File Component files.

For example:

vue
<script setup>
import { 
onMounted
,
r
ef
} from 'vue'
// reactive state const
count
=
ref
(0)
// functions that mutate state and trigger updates function
increment
() {
count
.
value
++
} // lifecycle hooks
onMounted
(() => {
console
.
log
(`The initial count is ${
count
.
value
}.`)
}) </script> <template> <
button
@
click
="
increment
">
Count is: {{
count
}}
</
button
>
</template>
vue
<script setup>
import { onMounted, ref } from 'vue'
//                   ^?

// reactive state
const count = ref(0)

// functions that mutate state and trigger updates
function increment() {
  count.value++
}

// lifecycle hooks
onMounted(() => {
  console.log(`The initial count is ${count.value}.`)
})
</script>

<template>
  <button @click="increment">
    Count is: {{ count }}
  </button>
</template>

Installation

bash
npm i -D twoslash-vue
bash
pnpm i -D twoslash-vue
bash
yarn add -D twoslash-vue
bash
bun add -D twoslash-vue

Usage

ts
import { 
createTwoSlasher
} from 'twoslash'
import {
createTwoSlasher
} from 'twoslash-vue'
const
code
= `
<script setup> const msg = 'Hello Vue 3!' </script> <template> <div> <h1></h1> </div> </template> ` const
twoslasher
=
createTwoSlasher
()
const
result
=
twoslasher
(
code
, 'vue')
ts
// @noErrors
import { createTwoSlasher } from 'twoslash'
import { createTwoSlasher } from 'twoslash-vue'

const code = `
<script setup>
const msg = 'Hello Vue 3!'
</script>

<template>
  <div>
    <h1>{{ msg }}</h1>
  </div>
</template>
`

const twoslasher = createTwoSlasher()
const result = twoslasher(code, 'vue')

Released under the MIT License.