shikijs / shiki

A beautiful yet powerful syntax highlighter

Home Page:http://shiki.style/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION] How to load type in twoslash when using auto import ?

gjssss opened this issue · comments

Validations

Describe the bug

Sorry, I haven't found the same issue yet.

I didn't know how to use twoslash with auto import or nuxt?
For Example

```ts
const { data } = useFetch('/api/hello')
```

without import, twoslash seems unable to get the type. But another problem is I didn't know how to import from nuxt. I try to use import { useFetch } from '#imports', it not work.

The full code and error blow.

server/api/height-light.post.ts

import {
  codeToHtml,
} from 'shiki'
import {
  transformerTwoslash,
} from '@shikijs/twoslash'

export default defineEventHandler(async (event) => {
  const { code } = await readBody<{ code: string }>(event)
  const html = await codeToHtml(code.trim(), {
    lang: 'ts',
    themes: {
      light: 'github-light',
      dark: 'github-dark',
    },
    transformers: [
      transformerTwoslash(),
    ],
  })
  return html
})

error

[nuxt] [request error] [unhandled] [500] 
## Errors were thrown in the sample, but not included in an error tag

These errors were not marked as being expected: 2304.
Expected: // @errors: 2304

Compiler Errors:

index.ts
  [2304] 17 - Cannot find name 'useFetch'.

Reproduction

above

Contributes

  • I am willing to submit a PR to fix this issue
  • I am willing to submit a PR with failing tests