mirror of
https://github.com/andatoshiki/toshiki-notebook.git
synced 2026-06-06 04:34:16 +00:00
10 lines
9.5 KiB
JavaScript
10 lines
9.5 KiB
JavaScript
import{_ as r}from"./chunks/PageInfo.vue_vue_type_script_setup_true_lang.250b3e56.js";import{_ as c,C as p,o as i,c as d,H as a,k as s,w as l,a as o,Q as n}from"./chunks/framework.b7580407.js";import"./chunks/commonjsHelpers.725317a4.js";const ys=JSON.parse('{"title":"Errors","description":"Raise compiler errors in your code examples to show incorrect states.","frontmatter":{"description":"Raise compiler errors in your code examples to show incorrect states.","title":"Errors"},"headers":[],"relativePath":"application/vitepress-plugin-shiki-twoslash/api/errors.md","filePath":"application/vitepress-plugin-shiki-twoslash/api/errors.md","lastUpdated":1694943391000}'),y={name:"application/vitepress-plugin-shiki-twoslash/api/errors.md"},h=s("h1",{id:"errors",tabindex:"-1"},[o("Errors "),s("a",{class:"header-anchor",href:"#errors","aria-label":'Permalink to "Errors"'},"")],-1),_=s("p",null,"Most of the time, you want to avoid errors in your code examples. Strictly speaking, this usually means setting the right compiler flags and environment in each code example.",-1),u=s("p",null,"Sometimes however, you do want to raise a compiler error — to show incorrect states. In those cases, twoslash has a way to mark the compiler errors you expect.",-1),m=s("h2",{id:"errors-num",tabindex:"-1"},[s("code",null,"@errors: [num]"),o(),s("a",{class:"header-anchor",href:"#errors-num","aria-label":'Permalink to "`@errors: [num]`"'},"")],-1),b=s("p",null,"All TypeScript compiler errors have a number, this number is relatively arbitrary and can change between TypeScript versions. For our case these numbers are useul in declaring what we expect to see.",-1),v=s("p",null,[o("You can use "),s("code",null,"// @errors: [num]"),o(" to tell Twoslash that you expect this error to occur. This moves the compiler error message into the code example.")],-1),g={class:"vp-code-group vp-adaptive-theme"},B=n("",1),k={class:"blocks"},w={class:"language-ts vp-adaptive-theme active line-numbers-mode"},A=s("button",{title:"Copy Code",class:"copy"},null,-1),f=s("span",{class:"lang"},"ts",-1),D={class:"shiki solarized-dark twoslash lsp",style:{"background-color":"#002B36",color:"#839496"}},E=s("div",{class:"language-id"},"ts",-1),T={class:"code-container"},C=s("div",{class:"line"},[s("span",{style:{color:"#93A1A1"}},"const"),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#268BD2"}},[s("data-lsp",{lsp:'const a: "123"'},"a")]),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#2AA198"}},"'123'")],-1),x={class:"line"},S={style:{color:"#268BD2"}},P=s("data-lsp",{lsp:"const a: any"},"a",-1),z=s("span",{style:{color:"#839496"}}," ",-1),I=s("span",{style:{color:"#859900"}},"=",-1),V=s("span",{style:{color:"#839496"}}," ",-1),q=s("span",{style:{color:"#D33682"}},"132",-1),N=s("span",{class:"error"},[s("span",null,"Cannot assign to 'a' because it is a constant."),s("span",{class:"code"},"2588")],-1),R=s("span",{class:"error-behind"},"Cannot assign to 'a' because it is a constant.",-1),F={class:"shiki solarized-light twoslash lsp",style:{"background-color":"#FDF6E3",color:"#657B83"}},H=s("div",{class:"language-id"},"ts",-1),O={class:"code-container"},U=s("div",{class:"line"},[s("span",{style:{color:"#586E75"}},"const"),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#268BD2"}},[s("data-lsp",{lsp:'const a: "123"'},"a")]),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#2AA198"}},"'123'")],-1),$={class:"line"},Y={style:{color:"#268BD2"}},J=s("data-lsp",{lsp:"const a: any"},"a",-1),M=s("span",{style:{color:"#657B83"}}," ",-1),L=s("span",{style:{color:"#859900"}},"=",-1),W=s("span",{style:{color:"#657B83"}}," ",-1),Z=s("span",{style:{color:"#D33682"}},"132",-1),j=s("span",{class:"error"},[s("span",null,"Cannot assign to 'a' because it is a constant."),s("span",{class:"code"},"2588")],-1),Q=s("span",{class:"error-behind"},"Cannot assign to 'a' because it is a constant.",-1),G=s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br")],-1),K=n("",1),X=s("h2",{id:"noerrors",tabindex:"-1"},[s("code",null,"@noErrors"),o(),s("a",{class:"header-anchor",href:"#noerrors","aria-label":'Permalink to "`@noErrors`"'},"")],-1),ss=s("p",null,[o("Sometimes you have needs in which a broken TypeScript build is okay. A good example of this is using a "),s("a",{href:"./queries#completions"},"completion query"),o(", which requires a broken TypeScript project to work. You can use "),s("code",null,"// @noErrors"),o(" to supress all errors in a code sample, and not have them show inline.")],-1),os=s("div",{class:"vp-code-group vp-adaptive-theme"},[s("div",{class:"tabs"},[s("input",{type:"radio",name:"group-lbBRy",id:"tab-foHkUDO",checked:"checked"}),s("label",{for:"tab-foHkUDO"},"output"),s("input",{type:"radio",name:"group-lbBRy",id:"tab-wu3IkLH"}),s("label",{for:"tab-wu3IkLH"},"markdown")]),s("div",{class:"blocks"},[s("div",{class:"language-ts vp-adaptive-theme active line-numbers-mode"},[s("button",{title:"Copy Code",class:"copy"}),s("span",{class:"lang"},"ts"),s("pre",{class:"shiki solarized-dark twoslash lsp",style:{"background-color":"#002B36",color:"#839496"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#93A1A1"}},"const"),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#268BD2"}},[s("data-lsp",{lsp:'const a: "123"'},"a")]),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#2AA198"}},"'123'")]),s("div",{class:"line"},[s("span",{style:{color:"#268BD2"}},[s("data-lsp",{lsp:"const a: any"},"a")]),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#D33682"}},"132")])])])]),s("pre",{class:"shiki solarized-light twoslash lsp",style:{"background-color":"#FDF6E3",color:"#657B83"}},[s("div",{class:"language-id"},"ts"),s("div",{class:"code-container"},[s("code",null,[s("div",{class:"line"},[s("span",{style:{color:"#586E75"}},"const"),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#268BD2"}},[s("data-lsp",{lsp:'const a: "123"'},"a")]),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#2AA198"}},"'123'")]),s("div",{class:"line"},[s("span",{style:{color:"#268BD2"}},[s("data-lsp",{lsp:"const a: any"},"a")]),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#D33682"}},"132")])])])]),s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br")])]),s("div",{class:"language-md vp-adaptive-theme line-numbers-mode"},[s("button",{title:"Copy Code",class:"copy"}),s("span",{class:"lang"},"md"),s("pre",{class:"shiki solarized-dark vp-code-dark"},[s("code",null,[s("span",{class:"line"},[s("span",{style:{color:"#839496"}},"```ts twoslash")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#586E75","font-style":"italic"}},"// @noErrors")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#93A1A1","font-weight":"bold"}},"const"),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#268BD2"}},"a"),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#2AA198"}},"'123'")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#268BD2"}},"a"),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#839496"}}," "),s("span",{style:{color:"#D33682"}},"132")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#839496"}},"```")])])]),s("pre",{class:"shiki solarized-light vp-code-light"},[s("code",null,[s("span",{class:"line"},[s("span",{style:{color:"#657B83"}},"```ts twoslash")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#93A1A1","font-style":"italic"}},"// @noErrors")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#586E75","font-weight":"bold"}},"const"),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#268BD2"}},"a"),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#2AA198"}},"'123'")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#268BD2"}},"a"),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#859900"}},"="),s("span",{style:{color:"#657B83"}}," "),s("span",{style:{color:"#D33682"}},"132")]),o(`
|
||
`),s("span",{class:"line"},[s("span",{style:{color:"#657B83"}},"```")])])]),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"),s("span",{class:"line-number"},"5"),s("br")])])])],-1);function as(es,ls,ns,ts,rs,cs){const t=r,e=p("data-err");return i(),d("div",null,[h,a(t,{readTime:"1",words:"227"}),_,u,m,b,v,s("div",g,[B,s("div",k,[s("div",w,[A,f,s("pre",D,[E,s("div",T,[s("code",null,[C,s("div",x,[s("span",S,[a(e,null,{default:l(()=>[P]),_:1})]),z,I,V,q]),N,R])])]),s("pre",F,[H,s("div",O,[s("code",null,[U,s("div",$,[s("span",Y,[a(e,null,{default:l(()=>[J]),_:1})]),M,L,W,Z]),j,Q])])]),G]),K])]),X,ss,os])}const hs=c(y,[["render",as]]);export{ys as __pageData,hs as default};
|