Show Emitted Files
Added in 0.6.0Running a Twoslash code sample is a full TypeScript compiler run, and that run will create files inside the virtual file system. You can replace the contents of your code sample with the results of running TypeScript over the project.
@showEmit
Section titled “@showEmit”// @showEmit is the main command to tell Twoslash that you want to replace the output of your code sample with the equivalent .js file.
const level = 'Danger';export {};```ts twoslash// @showEmitconst level: string = 'Danger'```Would show the .js file which this .ts file represents. You can see TypeScript add ‘use strict’ and : string is removed from the output.
@showEmittedFile: [file]
Section titled “@showEmittedFile: [file]”While the .js file is probably the most useful file out of the box, TypeScript does emit other files if you have the right flags enabled (.d.ts and .map) but also when you have a multi-file code sample - you might need to tell Twoslash which file to show. For all these cases you can also add @showEmittedFile: [file] to tell Twoslash which file you want to show.
.d.ts files
Section titled “.d.ts files”export declare const hello = "world";
```ts twoslash title="index.d.ts"// @declaration// @showEmit// @showEmittedFile: index.d.tsexport const hello = 'world'```.map for .js files
Section titled “.map for .js files”{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO,CAAA"}```ts twoslash title="index.js.map"// @sourceMap// @showEmit// @showEmittedFile: index.js.mapexport const hello = 'world'```.map for .d.ts files
Section titled “.map for .d.ts files”{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,EAAE,MAAgB,CAAA"}```ts twoslash title="index.d.ts.map"// @declaration// @declarationMap// @showEmit// @showEmittedFile: index.d.ts.mapexport const hello: string = 'world'```Multi-file code samples
Section titled “Multi-file code samples”// @filename: b.tsimport { helloWorld } from './a';console.log(helloWorld);
```ts twoslash title="b.js"// @showEmit// @showEmittedFile: b.js// @filename: a.tsexport const helloWorld: string = 'Hi';
// @filename: b.tsimport { helloWorld } from './a';
console.log(helloWorld);```