Tsolid
SolidJS extension that provides better TypeScript experience by allowing a way to writing JSX like React
Install / Use
/learn @nakasyou/TsolidREADME
tsolid
tsolid is a SolidJS extension that provides better TypeScript experience by allowing a way to writing JSX like React.
Why
SolidJS is very fast because it compiles JSX to fine-grained reactivity. However, by doing so, it has some constraints such as that you need to use Show, For, Index instead of short-curcuit evaluation (&&), Array.prototype.map. This is necessary to make your application fast, but it makes TypeScript experience worse than React.
For example:
const App = () => {
const value: string | number = 'Hello World'
return (
<Show when={typeof value === 'string'}>
<div>{
value.toUpperCase() // TS error: Property 'toUpperCase' does not exist on type 'string | number'
}</div>
</Show>
)
}
In React, you can write a code like typeof value === 'string' && <div>{value.toUpperCase()}</div> and TypeScript will narrow the type of value to string.
This library provides a way to write JSX like React, but still compiled code is fast like SolidJS.
For instance, you can write a code like this:
import { tsignal } from 'tsolid'
const App = () => {
const value = tsignal<string | number>('Hello World')
return (
<>
{typeof value() === 'string' && <div>{value().toUpperCase()}</div>}
</>
)
}
This code will be compiled to:
import { tsignal } from 'tsolid'
import { Show } from 'solid-js'
const App = () => {
const value = tsignal<string | number>('Hello World')
return (
<>
<Show when={typeof value.v === 'string'}>
<div>{value.v.toUpperCase()}</div>
</Show>
</>
)
}
And, tsolid also provides a better Signal API, signal.
If you are using createSignal, a TypeScript inferce is sometimes not good:
const [value, setValue] = createSignal<string | null>('Hello World')
if (value() === null) {
// TS error: Type 'null' is not assignable to type 'string'
value().toUpperCase()
}
This is because getting signal value is a function, so TypeScript cannot infer the type of value correctly.
So, tsolid provides a better signal API, tsignal, which can get value by getter/setter using v.
import { tsignal } from 'tsolid'
const value = tsignal<string | null>('Hello World')
if (value.v === null) {
// OK
value.v.toUpperCase()
}
Installation
bun add tsolid # Bun
deno add npm:tsolid # Deno
pnpm add tsolid # pnpm
yarn add tsolid # yarn
npm install tsolid # npm
If you are using Vite, you need to add the following to your vite.config.ts:
import { defineConfig } from 'vite'
import solidPlugin from 'vite-plugin-solid'
import tsolid from 'tsolid/babel'
export default defineConfig({
plugins: [
solidPlugin({
babel: {
plugins: [
// add here
tsolid(),
],
}
}),
],
})
Related Skills
qqbot-channel
349.7kQQ 频道管理技能。查询频道列表、子频道、成员、发帖、公告、日程等操作。使用 qqbot_channel_api 工具代理 QQ 开放平台 HTTP 接口,自动处理 Token 鉴权。当用户需要查看频道、管理子频道、查询成员、发布帖子/公告/日程时使用。
docs-writer
100.4k`docs-writer` skill instructions As an expert technical writer and editor for the Gemini CLI project, you produce accurate, clear, and consistent documentation. When asked to write, edit, or revie
model-usage
349.7kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
Design
Campus Second-Hand Trading Platform \- General Design Document (v5.0 \- React Architecture \- Complete Final Version)1\. System Overall Design 1.1. Project Overview This project aims t
