toshiki-notebook/assets/application_vitepress-plugin-shiki-twoslash_api_errors.md.ef253d66.js

10 lines
12 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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":1695144785000}'),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('<div class="tabs"><input type="radio" name="group-e1-s5" id="tab-_-DpDMz" checked="checked"><label for="tab-_-DpDMz">output</label><input type="radio" name="group-e1-s5" id="tab-_9dp98B"><label for="tab-_9dp98B">markdown</label></div>',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),D=s("span",{class:"lang"},"ts",-1),f={class:"shiki solarized-dark twoslash lsp",style:{"background-color":"#002B36",color:"#839496"}},T=s("div",{class:"language-id"},"ts",-1),E={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"}},z=s("data-lsp",{lsp:"const a: any"},"a",-1),P=s("span",{style:{color:"#839496"}}," ",-1),V=s("span",{style:{color:"#859900"}},"=",-1),F=s("span",{style:{color:"#839496"}}," ",-1),N=s("span",{style:{color:"#D33682"}},"132",-1),I=s("span",{class:"error"},[s("span",null,"Cannot assign to 'a' because it is a constant."),s("span",{class:"code"},"2588")],-1),$=s("span",{class:"error-behind"},"Cannot assign to 'a' because it is a constant.",-1),R={class:"shiki solarized-light twoslash lsp",style:{"background-color":"#FDF6E3",color:"#657B83"}},Y=s("div",{class:"language-id"},"ts",-1),q={class:"code-container"},M=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),U={class:"line"},L={style:{color:"#268BD2"}},W=s("data-lsp",{lsp:"const a: any"},"a",-1),j=s("span",{style:{color:"#657B83"}}," ",-1),H=s("span",{style:{color:"#859900"}},"=",-1),J=s("span",{style:{color:"#657B83"}}," ",-1),O=s("span",{style:{color:"#D33682"}},"132",-1),Q=s("span",{class:"error"},[s("span",null,"Cannot assign to 'a' because it is a constant."),s("span",{class:"code"},"2588")],-1),G=s("span",{class:"error-behind"},"Cannot assign to 'a' because it is a constant.",-1),K=s("div",{class:"line-numbers-wrapper","aria-hidden":"true"},[s("span",{class:"line-number"},"1"),s("br")],-1),X=n('<div class="language-md vp-adaptive-theme line-numbers-mode"><button title="Copy Code" class="copy"></button><span class="lang">md</span><pre class="shiki solarized-dark vp-code-dark"><code><span class="line"><span style="color:#839496;">```ts twoslash</span></span>\n<span class="line"><span style="color:#586E75;font-style:italic;">// @errors: 2588</span></span>\n<span class="line"><span style="color:#93A1A1;font-weight:bold;">const</span><span style="color:#839496;"> </span><span style="color:#268BD2;">a</span><span style="color:#839496;"> </span><span style="color:#859900;">=</span><span style="color:#839496;"> </span><span style="color:#2AA198;">&#39;123&#39;</span></span>\n<span class="line"><span style="color:#268BD2;">a</span><span style="color:#839496;"> </span><span style="color:#859900;">=</span><span style="color:#839496;"> </span><span style="color:#D33682;">132</span></span>\n<span class="line"><span style="color:#839496;">```</span></span></code></pre><pre class="shiki solarized-light vp-code-light"><code><span class="line"><span style="color:#657B83;">```ts twoslash</span></span>\n<span class="line"><span style="color:#93A1A1;font-style:italic;">// @errors: 2588</span></span>\n<span class="line"><span style="color:#586E75;font-weight:bold;">const</span><span style="color:#657B83;"> </span><span style="color:#268BD2;">a</span><span style="color:#657B83;"> </span><span style="color:#859900;">=</span><span style="color:#657B83;"> </span><span style="color:#2AA198;">&#39;123&#39;</span></span>\n<span class="line"><span style="color:#268BD2;">a</span><span style="color:#657B83;"> </span><span style="color:#859900;">=</span><span style="color:#657B83;"> </span><span style="color:#D33682;">132</span></span>\n<span class="line"><span style="color:#657B83;">```</span></span></code></pre><div class="line-numbers-wrapper" aria-hidden="true"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div>',1),Z=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-FgoYW",id:"tab-tL52dT0",checked:"checked"}),s("label",{for:"tab-tL52dT0"},"output"),s("input",{type:"radio",name:"group-FgoYW",id:"tab-TpU0ns5"}),s("label",{for:"tab-TpU0ns5"},"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,D,s("pre",f,[T,s("div",E,[s("code",null,[C,s("div",x,[s("span",S,[a(e,null,{default:l(()=>[z]),_:1})]),P,V,F,N]),I,$])])]),s("pre",R,[Y,s("div",q,[s("code",null,[M,s("div",U,[s("span",L,[a(e,null,{default:l(()=>[W]),_:1})]),j,H,J,O]),Q,G])])]),K]),X])]),Z,ss,os])}const hs=c(y,[["render",as]]);export{ys as __pageData,hs as default};