Skip to content

External Types

Unless you’re teaching TypeScript/JavaScript, you’re probably going to want to import libraries into your code samples.

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.

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.

import {
function writeFileSync(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void

Returns undefined.

The mode option only affects the newly created file. See

open

for more details.

For detailed information, see the documentation of the asynchronous version of this API:

writeFile

.

@sincev0.1.29

@paramfile filename or file descriptor

writeFileSync
} from "node:fs";
function writeFileSync(file: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): void

Returns undefined.

The mode option only affects the newly created file. See

open

for more details.

For detailed information, see the documentation of the asynchronous version of this API:

writeFile

.

@sincev0.1.29

@paramfile filename or file descriptor

writeFileSync
("myfile.txt", "// TODO");