Queries
Author:Anda Toshiki
Updated:2 months 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
consthi = 'Hello'constmsg =hi + ', world'
ts
consthi = 'Hello'constmsg =hi + ', world'
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.