Skip to content

Queries

Author:Anda Toshiki
Updated:6 days ago
Words:167
Reading:1 min

One of the key features of Twoslash is the ability to use the TypeScript compiler to pull out type information about your code. Twoslash comes with two different ways to query your code: ?^ and ?|.

Extract Type ^?

Using ^? you can pull out type information about a particular identifier in the line of code above it.

ts
ts
const hi = 'Hello'
const msg = hi + ', world'
const msg: string
ts
const hi = 'Hello'
const msg = hi + ', world'
const msg: string
md
```ts twoslash
const hi = 'Hello'
const msg = hi + ', world'
//    ^?
```
```ts twoslash
const hi = 'Hello'
const msg = hi + ', world'
//    ^?
```

Completions ^|

Using ^| you can pull out information about a what the auto-complete looks like at a particular location.

ts
ts
console.e
         
ts
console.e
         
md
```ts twoslash
// @noErrors
console.e
//       ^|
```
```ts twoslash
// @noErrors
console.e
//       ^|
```

INFO

Note that the compiler flag for // @noErrors is set, because console.e is a failing TypeScript code sample but we don't really care about that.