Twoslash
এই ফিচারটি Twoslash থেকে নেয়া।
সব টাইপস্ক্রিপ্ট কোড ব্লক inline type hover প্রোভাইড করে।
twoslash চালু করা
- @sveltepress/twoslash প্যাকেজ ইন্সটল করুন
npm install --save @sveltepress/twoslash highlighter.twoslashকনফিগ করেtrueকরে দিন
import { defaultTheme } from '@sveltepress/theme-default'
import { sveltepress } from '@sveltepress/vite'
import { defineConfig } from 'vite'
export default defineConfig ({
plugins : [
sveltepress ({
theme : defaultTheme ({
highlighter : {
twoslash : true
}
})
})
]
}) প্রাথমিক type annotation
const foo = false
const obj = {
a : 'a',
b : 1
} ```ts
const foo = false
const obj = {
a: 'a',
b: 1
}
``` এরোর
const foo : Foo = null
const a: number = '1' ```ts
// @errors: 2304 2322
const foo: Foo = null
const a: number = '1'
``` কুয়েরি
const hi = 'Hello'
const msg = `${hi }, world`
//
//
Number .p arseInt ('123', 10)
//
//
//
// ```ts
const hi = 'Hello'
const msg = `${hi}, world`
// ^?
//
//
Number.parseInt('123', 10)
// ^|
//
//
//
//
``` কাস্টম লগ
const a = 1Custom log message
const b = 1Custom error message
const c = 1Custom warning message
Custom annotation message ```ts
// @log: Custom log message
const a = 1
// @error: Custom error message
const b = 1
// @warn: Custom warning message
const c = 1
// @annotate: Custom annotation message
``` কাট কোডস
আগে কাট
// ---cut--- বা // ---cut-before--- ব্যবহার করে এই লাইনের পূর্বের সকল কোড কাট করা যাবে।
console .log (level ) ```ts
const level: string = 'Danger'
// ---cut---
console.log(level)
``` পরে কাট
// ---cut-after--- বহার করে এই লাইনের পরের সকল কোড কাট করা যাবে।
console .log (level )
```ts
const level: string = 'Danger'
// ---cut-before---
console.log(level)
// ---cut-after---
console.log('This is not shown')
``` কাট শুরু/শেষ
আইটেমের মাঝের কন্টেন্ট কাট করতে // ---cut-start--- বা // ---cut-end--- ব্যবহার করুন
const level : string = 'Danger'
console .log ('This is shown') ```ts
const level: string = 'Danger'
// ---cut-start---
console.log(level) // This is not shown.
// ---cut-end---
console.log('This is shown')
``` svelte এর জন্য Twoslash
<script>
import { onMount } from 'svelte'
let count = $ state (0)
onMount (() => {
// mounted
})
</script>
<button onclick={count ++}>
Count is: {count }
</button>