# @types | Toshiki's Note
Using external libraries with Twoslash code examples.
Author: Anda Toshiki
Keywords: Toshiki, Anda Toshiki, andatoshiki, GitHub, GitHub action, Vitepress, Vite, Notebook, Knowledge base, Programming, Programming Notes, Academic, Personal, Notebook, Productivity, Journal, Note-taking, Markdown, Notepad, Organization, Tutorial

Skip to content

####

# @types ​

Author:Anda Toshiki
Updated:a minute ago
Words:230
Reading:1 min

For most examples, you probably need to import external libraries into your code examples.

Twoslash works by faking a virtual file system over your existing file system. This means any `@types` or libraries with TypeScript definitions should work out of the box with no config.

## Local Sources ​

Simply import locally installed libraries and Twoslash can pick up types:

outputmarkdown
ts

    tsimport { defineConfig } from 'vitepress'const config = defineConfig({})        const config: UserConfig<DefaultTheme.Config>export default config

    tsimport { defineConfig } from 'vitepress'const config = defineConfig({})        const config: UserConfig<DefaultTheme.Config>export default config

1
md

    ```ts twoslash
    import { defineConfig } from 'vitepress'
    const config = defineConfig({})
    //    ^?
    export default config
    ```

    ```ts twoslash
    import { defineConfig } from 'vitepress'
    const config = defineConfig({})
    //    ^?
    export default config
    ```

1
2
3
4
5
6

## Globals ​

Setting up globals is a little bit more complex, but not drastically. You need to use the triple slash reference which adds a particular library to the global scope.

For example, setting up Node imports and globals etc.

outputmarkdown
ts

    tsimport { writeFileSync } from 'fs'writeFileSync('myfile.txt', '// TODO')

    tsimport { writeFileSync } from 'fs'writeFileSync('myfile.txt', '// TODO')

1
md

    ```ts twoslash
    /// <reference types="node" />
    // ---cut---
    import { writeFileSync } from 'fs'
    writeFileSync('myfile.txt', '// TODO')
    ```

    ```ts twoslash
    /// <reference types="node" />
    // ---cut---
    import { writeFileSync } from 'fs'
    writeFileSync('myfile.txt', '// TODO')
    ```

1
2
3
4
5
6

APIs like Vitest are similar cases where you would use a triple slash reference.

outputmarkdown
ts

    tstest('my tests', () => {    expect('hello').toEqual('hello')      const expect: ExpectStatic})

    tstest('my tests', () => {    expect('hello').toEqual('hello')      const expect: ExpectStatic})

1
md

    ```ts twoslash
    /// <reference types="vitest/globals" />
    // ---cut---

    test('my tests', () => {
        expect('hello').toEqual('hello')
        // ^?
    })
    ```

    ```ts twoslash
    /// <reference types="vitest/globals" />
    // ---cut---

    test('my tests', () => {
        expect('hello').toEqual('hello')
        // ^?
    })
    ```

1
2
3
4
5
6
7
8
9