Skip to content

Code Cutting

Every Twoslash code sample needs to be a complete TypeScript program realistically, basically it needs to compile. Quite often to make it compile, there is a bunch of code which isn’t relevant to the user. This can be extracted out of the code sample via the following flags to remove code from the output.

cut-before and cut

Cut works after TypeScript has generated the project and pulled out all the editor information (like identifiers, queries, highlights etc) and then amends all of their offsets and lines to re-fit the smaller output. What your user sees is everything below the // ---cut-before---. A shorthand // ---cut--- is also available.

console.log(level)

cut-after

The sibling to // ---cut-before--- which trims anything after the flag.

console.log(level)

cut-start and cut-end

You can also use // ---cut-start--- and // ---cut-end--- pairs to cut out sections of code in between the two flags.

const level: string = 'Danger'
console.log('This is shown')