Skip to Content
🎉 Nextra 4.0 已发布。Dima Machina 正在 寻找新的工作或咨询机会
DocumentationAdvancedTwoslash 支持

Twoslash 支持

Twoslash 在代码块中提供内联类型悬停提示。

基础用法

您可以通过添加 twoslash 元数据来为代码块启用 twoslash:

Markdown
```ts twoslash // @errors: 2540 interface Todo { title: string } const todo: Readonly<Todo> = { title: 'Delete inactive users'.toUpperCase() // ^? } todo.title = 'Hello' Number.parseInt('123', 10) // ^| // Just comments, so Popup will be // not behind the viewport of `<code>` // element due his `position: absolute` style // ```

渲染结果:

interface Todo { : string } const : <Todo> = {
title: string
title
: 'Delete inactive users'.()
} .title = 'Hello'
Cannot assign to 'title' because it is a read-only property.
.p
  • parseFloat
  • parseInt
  • prototype
('123', 10)

自定义日志消息

您可以通过添加以下内容来为代码添加日志消息:

  • @log: <message> 自定义日志消息
  • @error: <message> 自定义错误消息
  • @warn: <message> 自定义警告消息
  • @annotate: <message> 自定义注释消息
const = 1
自定义日志消息
const = 1
自定义错误消息
const = 1
自定义警告消息
自定义注释消息
Last updated on