import{_ as o}from"./chunks/PageInfo.vue_vue_type_script_setup_true_lang.250b3e56.js";import{_ as n,o as p,c as t,H as r,k as s,a as l,Q as e}from"./chunks/framework.b7580407.js";import"./chunks/commonjsHelpers.725317a4.js";const q=JSON.parse('{"title":"VitePress Twoslash: VitePress Plugin for Shiki Twoslash","titleTemplate":false,"description":"Static code examples for VitePress using Shiki Twoslash.","frontmatter":{"description":"Static code examples for VitePress using Shiki Twoslash.","title":"VitePress Twoslash: VitePress Plugin for Shiki Twoslash","titleTemplate":false,"keywords":["getting-started","intro"]},"headers":[],"relativePath":"application/vitepress-plugin-shiki-twoslash/index.md","filePath":"application/vitepress-plugin-shiki-twoslash/index.md","lastUpdated":1710267201000}'),c={name:"application/vitepress-plugin-shiki-twoslash/index.md"},i=s("h1",{id:"andatoshiki-vitepress-plugin-shiki-twoslash",tabindex:"-1"},[l("@andatoshiki/vitepress-plugin-shiki-twoslash "),s("a",{class:"header-anchor",href:"#andatoshiki-vitepress-plugin-shiki-twoslash","aria-label":'Permalink to "@andatoshiki/vitepress-plugin-shiki-twoslash"'},"​")],-1),y=s("blockquote",null,[s("p",null,[l("Static code examples for "),s("a",{href:"https://vitepress.dev",target:"_blank",rel:"noreferrer"},"VitePress"),l(" using "),s("a",{href:"https://github.com/shikijs/twoslash",target:"_blank",rel:"noreferrer"},"Shiki Twoslash"),l(" — powered by the syntax engine of Visual Studio Code and the TypeScript compiler.")])],-1),d=s("h2",{id:"overview",tabindex:"-1"},[l("Overview "),s("a",{class:"header-anchor",href:"#overview","aria-label":'Permalink to "Overview"'},"​")],-1),u=s("p",null,"Try moving your cursor into the code block below:",-1),A=s("div",{class:"language-ts vp-adaptive-theme line-numbers-mode"},[s("button",{title:"Copy Code",class:"copy"}),s("span",{class:"lang"},"ts"),s("pre",{class:"shiki github-dark-dimmed twoslash lsp",style:{"background-color":"#22272e",color:"#adbac7"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#768390"}},"// Removes 'readonly' attributes from a type's properties")]),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"type"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#ADBAC7"}},"<"),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#ADBAC7"}},"> "),s("span",{style:{color:"#F47067"}},"="),s("span",{style:{color:"#ADBAC7"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"-readonly"),s("span",{style:{color:"#ADBAC7"}}," ["),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"in"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"keyof"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#ADBAC7"}},"]"),s("span",{style:{color:"#F47067"}},":"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#ADBAC7"}},"["),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#ADBAC7"}},"]")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"type"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"="),s("span",{style:{color:"#ADBAC7"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"readonly"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(property) id: string"},"id")]),s("span",{style:{color:"#F47067"}},":"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#6CB6FF"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"readonly"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(property) name: string"},"name")]),s("span",{style:{color:"#F47067"}},":"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#6CB6FF"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"type"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:`type UnlockedAccount = { id: string; name: string; }`},"UnlockedAccount")]),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"="),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#ADBAC7"}},"<"),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#ADBAC7"}},">")])])])]),s("pre",{class:"shiki github-light twoslash lsp",style:{"background-color":"#fff",color:"#24292e"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#6A737D"}},"// Removes 'readonly' attributes from a type's properties")]),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"type"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#24292E"}},"<"),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#24292E"}},"> "),s("span",{style:{color:"#D73A49"}},"="),s("span",{style:{color:"#24292E"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"-readonly"),s("span",{style:{color:"#24292E"}}," ["),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"in"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"keyof"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#24292E"}},"]"),s("span",{style:{color:"#D73A49"}},":"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#24292E"}},"["),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#24292E"}},"]")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"type"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"="),s("span",{style:{color:"#24292E"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"readonly"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#E36209"}},[s("data-lsp",{lsp:"(property) id: string"},"id")]),s("span",{style:{color:"#D73A49"}},":"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#005CC5"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"readonly"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#E36209"}},[s("data-lsp",{lsp:"(property) name: string"},"name")]),s("span",{style:{color:"#D73A49"}},":"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#005CC5"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"type"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`type UnlockedAccount = { id: string; name: string; }`},"UnlockedAccount")]),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"="),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#24292E"}},"<"),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#24292E"}},">")])])])]),s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br")])],-1),h=s("p",null,"Pretty neat, right? To some extent, anything your editor can show you about code, Twoslash can show. For example, here is the real auto-complete for a VitePress config:",-1),C=s("div",{class:"language-ts vp-adaptive-theme line-numbers-mode"},[s("button",{title:"Copy Code",class:"copy"}),s("span",{class:"lang"},"ts"),s("pre",{class:"shiki github-dark-dimmed twoslash lsp",style:{"background-color":"#22272e",color:"#adbac7"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"import"),s("span",{style:{color:"#ADBAC7"}},[l(" { "),s("data-lsp",{lsp:`(alias) function defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig"),l(" } ")]),s("span",{style:{color:"#F47067"}},"from"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#96D0FF"}},"'vitepress'")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"export"),s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#F47067"}},"default"),s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#DCBDFB"}},[s("data-lsp",{lsp:`(alias) defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig")]),s("span",{style:{color:"#F69D50"}},"({")]),s("div",{class:"line"},[s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#ADBAC7"}},[s("data-lsp",{lsp:"(property) ti: any"},"ti")]),s("span",{style:{color:"#F69D50"}},",")]),s("div",{class:"meta-line"},[l("      "),s("span",{class:"inline-completions"},[s("ul",{class:"dropdown"},[s("li",{class:""},[s("span",null,[s("span",{class:"result-found"},"ti"),l("tle")])]),s("li",{class:""},[s("span",null,[s("span",{class:"result-found"},"ti"),l("tleTemplate")])])])])]),s("div",{class:"line"},[s("span",{style:{color:"#F69D50"}},"})")])])])]),s("pre",{class:"shiki github-light twoslash lsp",style:{"background-color":"#fff",color:"#24292e"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"import"),s("span",{style:{color:"#24292E"}},[l(" { "),s("data-lsp",{lsp:`(alias) function defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig"),l(" } ")]),s("span",{style:{color:"#D73A49"}},"from"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#032F62"}},"'vitepress'")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"export"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"default"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`(alias) defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig")]),s("span",{style:{color:"#24292E"}},"({")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}},[l(" "),s("data-lsp",{lsp:"(property) ti: any"},"ti"),l(",")])]),s("div",{class:"meta-line"},[l("      "),s("span",{class:"inline-completions"},[s("ul",{class:"dropdown"},[s("li",{class:""},[s("span",null,[s("span",{class:"result-found"},"ti"),l("tle")])]),s("li",{class:""},[s("span",null,[s("span",{class:"result-found"},"ti"),l("tleTemplate")])])])])]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}},"})")])])])]),s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br")])],-1),m=e(`

The name Twoslash refers to specially formatted comments (e.g. // ^?) which can be used to set up your environment, like compiler flags or separate input files. It couldn't be easier to set up and start creating incredible code examples!

Install

Install @andatoshiki/vitepress-plugin-shiki-twoslash (requires vitepress@>=1.0.0-alpha.61).

bash
pnpm add @andatoshiki/vitepress-plugin-shiki-twoslash
pnpm add @andatoshiki/vitepress-plugin-shiki-twoslash
bash
npm i @andatoshiki/vitepress-plugin-shiki-twoslash
npm i @andatoshiki/vitepress-plugin-shiki-twoslash
bash
yarn add @andatoshiki/vitepress-plugin-shiki-twoslash
yarn add @andatoshiki/vitepress-plugin-shiki-twoslash

WARNING

Until shiki-twoslash uses the same version of shiki as VitePress, you must override the following packages' shiki versions for syntax highlighting to look the same.

json
{
    "pnpm": {
        "overrides": {
            "remark-shiki-twoslash>shiki": "^0.14.1",
            "shiki-twoslash>shiki": "^0.14.1"
        }
    }
}
{
    "pnpm": {
        "overrides": {
            "remark-shiki-twoslash>shiki": "^0.14.1",
            "shiki-twoslash>shiki": "^0.14.1"
        }
    }
}

Tracked in an upstream issue: https://github.com/shikijs/twoslash/issues/180

Configure

First, wrap your VitePress config file with the withTwoslash wrapper.

`,7),g=s("div",{class:"language-ts vp-adaptive-theme line-numbers-mode"},[s("button",{title:"Copy Code",class:"copy"}),s("span",{class:"lang"},"ts"),s("pre",{class:"shiki github-dark-dimmed twoslash lsp",style:{"background-color":"#22272e",color:"#adbac7"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#768390"}},"// .vitepress/config.[ext]")]),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"import"),s("span",{style:{color:"#ADBAC7"}},[l(" { "),s("data-lsp",{lsp:`(alias) function defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig"),l(" } ")]),s("span",{style:{color:"#F47067"}},"from"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#96D0FF"}},"'vitepress'")]),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"import"),s("span",{style:{color:"#ADBAC7"}},[l(" { "),s("data-lsp",{lsp:`(alias) function withTwoslash(config: UserConfig): Promise> import withTwoslash`},"withTwoslash"),l(" } ")]),s("span",{style:{color:"#F47067"}},"from"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#96D0FF"}},"'@andatoshiki/vitepress-plugin-shiki-twoslash'")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"export"),s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#F47067"}},"default"),s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#DCBDFB"}},[s("data-lsp",{lsp:`(alias) withTwoslash(config: UserConfig): Promise> import withTwoslash`},"withTwoslash")]),s("span",{style:{color:"#F69D50"}},"(")]),s("div",{class:"line"},[s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#DCBDFB"}},[s("data-lsp",{lsp:`(alias) defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig")]),s("span",{style:{color:"#F69D50"}},"({")]),s("div",{class:"line"},[s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#768390"}},"// Your VitePress config")]),s("div",{class:"line"},[s("span",{style:{color:"#F69D50"}}," })")]),s("div",{class:"line"},[s("span",{style:{color:"#F69D50"}},")")])])])]),s("pre",{class:"shiki github-light twoslash lsp",style:{"background-color":"#fff",color:"#24292e"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#6A737D"}},"// .vitepress/config.[ext]")]),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"import"),s("span",{style:{color:"#24292E"}},[l(" { "),s("data-lsp",{lsp:`(alias) function defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig"),l(" } ")]),s("span",{style:{color:"#D73A49"}},"from"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#032F62"}},"'vitepress'")]),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"import"),s("span",{style:{color:"#24292E"}},[l(" { "),s("data-lsp",{lsp:`(alias) function withTwoslash(config: UserConfig): Promise> import withTwoslash`},"withTwoslash"),l(" } ")]),s("span",{style:{color:"#D73A49"}},"from"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#032F62"}},"'@andatoshiki/vitepress-plugin-shiki-twoslash'")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"export"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"default"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`(alias) withTwoslash(config: UserConfig): Promise> import withTwoslash`},"withTwoslash")]),s("span",{style:{color:"#24292E"}},"(")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`(alias) defineConfig(config: UserConfig): UserConfig import defineConfig`},"defineConfig")]),s("span",{style:{color:"#24292E"}},"({")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6A737D"}},"// Your VitePress config")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," })")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}},")")])])])]),s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br")])],-1),D=s("p",null,[l("Then, import "),s("code",null,"@andatoshiki/vitepress-plugin-shiki-twoslash/styles.css"),l(" into your theme.")],-1),f=s("div",{class:"language-ts vp-adaptive-theme line-numbers-mode"},[s("button",{title:"Copy Code",class:"copy"}),s("span",{class:"lang"},"ts"),s("pre",{class:"shiki github-dark-dimmed twoslash lsp",style:{"background-color":"#22272e",color:"#adbac7"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#768390"}},"// .vitepress/theme/index.ts")]),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"import"),s("span",{style:{color:"#ADBAC7"}},[l(),s("data-lsp",{lsp:`(alias) const defaultTheme: { Layout: DefineComponent; enhanceApp: (ctx: EnhanceAppContext) => void; } import defaultTheme`},"defaultTheme"),l()]),s("span",{style:{color:"#F47067"}},"from"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#96D0FF"}},"'vitepress/theme'")]),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"import"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#96D0FF"}},"'@andatoshiki/vitepress-plugin-shiki-twoslash/styles.css'")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"export"),s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#F47067"}},"default"),s("span",{style:{color:"#F69D50"}}," "),s("span",{style:{color:"#ADBAC7"}},[s("data-lsp",{lsp:`(alias) const defaultTheme: { Layout: DefineComponent; enhanceApp: (ctx: EnhanceAppContext) => void; } import defaultTheme`},"defaultTheme")])])])])]),s("pre",{class:"shiki github-light twoslash lsp",style:{"background-color":"#fff",color:"#24292e"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#6A737D"}},"// .vitepress/theme/index.ts")]),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"import"),s("span",{style:{color:"#24292E"}},[l(),s("data-lsp",{lsp:`(alias) const defaultTheme: { Layout: DefineComponent; enhanceApp: (ctx: EnhanceAppContext) => void; } import defaultTheme`},"defaultTheme"),l()]),s("span",{style:{color:"#D73A49"}},"from"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#032F62"}},"'vitepress/theme'")]),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"import"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#032F62"}},"'@andatoshiki/vitepress-plugin-shiki-twoslash/styles.css'")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"export"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"default"),s("span",{style:{color:"#24292E"}},[l(),s("data-lsp",{lsp:`(alias) const defaultTheme: { Layout: DefineComponent; enhanceApp: (ctx: EnhanceAppContext) => void; } import defaultTheme`},"defaultTheme")])])])])]),s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br")])],-1),v=e(`

TIP

You can configure VitePress Twoslash using the twoslash property added to defineConfig.

Add Twoslash

Finally, add the twoslash attribute to markdown fenced code blocks.

md
\`\`\`ts twoslash
// Removes 'readonly' attributes from a type's properties
type CreateMutable<Type> = {
    -readonly [Property in keyof Type]: Type[Property]
}

type LockedAccount = {
    readonly id: string
    readonly name: string
}

type UnlockedAccount = CreateMutable<LockedAccount>
//   ^?
\`\`\`
\`\`\`ts twoslash
// Removes 'readonly' attributes from a type's properties
type CreateMutable<Type> = {
    -readonly [Property in keyof Type]: Type[Property]
}

type LockedAccount = {
    readonly id: string
    readonly name: string
}

type UnlockedAccount = CreateMutable<LockedAccount>
//   ^?
\`\`\`

And your code blocks will be twoslashified!

`,5),b=s("div",{class:"language-ts vp-adaptive-theme line-numbers-mode"},[s("button",{title:"Copy Code",class:"copy"}),s("span",{class:"lang"},"ts"),s("pre",{class:"shiki github-dark-dimmed twoslash lsp",style:{"background-color":"#22272e",color:"#adbac7"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#768390"}},"// Removes 'readonly' attributes from a type's properties")]),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"type"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#ADBAC7"}},"<"),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#ADBAC7"}},"> "),s("span",{style:{color:"#F47067"}},"="),s("span",{style:{color:"#ADBAC7"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"-readonly"),s("span",{style:{color:"#ADBAC7"}}," ["),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"in"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"keyof"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#ADBAC7"}},"]"),s("span",{style:{color:"#F47067"}},":"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#ADBAC7"}},"["),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#ADBAC7"}},"]")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"type"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"="),s("span",{style:{color:"#ADBAC7"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"readonly"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(property) id: string"},"id")]),s("span",{style:{color:"#F47067"}},":"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#6CB6FF"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"readonly"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"(property) name: string"},"name")]),s("span",{style:{color:"#F47067"}},":"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#6CB6FF"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#ADBAC7"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#F47067"}},"type"),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:`type UnlockedAccount = { id: string; name: string; }`,style:{"border-bottom":"solid 2px lightgrey"}},"UnlockedAccount")]),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F47067"}},"="),s("span",{style:{color:"#ADBAC7"}}," "),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#ADBAC7"}},"<"),s("span",{style:{color:"#F69D50"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#ADBAC7"}},">")]),s("div",{class:"meta-line"},[s("span",{class:"popover-prefix"}," "),s("span",{class:"popover"},[s("div",{class:"arrow"}),l(`type UnlockedAccount = { id: string; name: string; }`)])])])])]),s("pre",{class:"shiki github-light twoslash lsp",style:{"background-color":"#fff",color:"#24292e"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#6A737D"}},"// Removes 'readonly' attributes from a type's properties")]),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"type"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#24292E"}},"<"),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#24292E"}},"> "),s("span",{style:{color:"#D73A49"}},"="),s("span",{style:{color:"#24292E"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"-readonly"),s("span",{style:{color:"#24292E"}}," ["),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"in"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"keyof"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#24292E"}},"]"),s("span",{style:{color:"#D73A49"}},":"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Type in type CreateMutable"},"Type")]),s("span",{style:{color:"#24292E"}},"["),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"(type parameter) Property"},"Property")]),s("span",{style:{color:"#24292E"}},"]")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"type"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"="),s("span",{style:{color:"#24292E"}}," {")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"readonly"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#E36209"}},[s("data-lsp",{lsp:"(property) id: string"},"id")]),s("span",{style:{color:"#D73A49"}},":"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#005CC5"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"readonly"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#E36209"}},[s("data-lsp",{lsp:"(property) name: string"},"name")]),s("span",{style:{color:"#D73A49"}},":"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#005CC5"}},"string")]),s("div",{class:"line"},[s("span",{style:{color:"#24292E"}},"}")]),s("div",{class:"line"}," "),s("div",{class:"line"},[s("span",{style:{color:"#D73A49"}},"type"),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`type UnlockedAccount = { id: string; name: string; }`,style:{"border-bottom":"solid 2px lightgrey"}},"UnlockedAccount")]),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#D73A49"}},"="),s("span",{style:{color:"#24292E"}}," "),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:"type CreateMutable = { -readonly [Property in keyof Type]: Type[Property]; }"},"CreateMutable")]),s("span",{style:{color:"#24292E"}},"<"),s("span",{style:{color:"#6F42C1"}},[s("data-lsp",{lsp:`type LockedAccount = { readonly id: string; readonly name: string; }`},"LockedAccount")]),s("span",{style:{color:"#24292E"}},">")]),s("div",{class:"meta-line"},[s("span",{class:"popover-prefix"}," "),s("span",{class:"popover"},[s("div",{class:"arrow"}),l(`type UnlockedAccount = { id: string; name: string; }`)])])])])]),s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br"),s("span",{class:"line-number"},"2"),s("br"),s("span",{class:"line-number"},"3"),s("br"),s("span",{class:"line-number"},"4"),s("br")])],-1);function F(k,T,E,B,w,_){const a=o;return p(),t("div",null,[i,r(a,{readTime:"2",words:"437"}),y,d,u,A,h,C,m,g,D,f,v,b])}const M=n(c,[["render",F]]);export{q as __pageData,M as default};