소개
Svelte 컴포넌트의 TypeScript 정의와 컴포넌트 문서를 생성합니다.
웹 및 앱 개발측정된 스타 증가
- in 24h
- 0
- in 7 days
- -2
- in 15 days
- -2
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalsveld
Generate TypeScript definitions and component documentation for your Svelte components.
sveld reads your components' props, events, slots, snippets and context, and the JSDoc where inference isn't enough, and writes .d.ts files your users' editors type-check against, plus JSON and Markdown docs from the same pass. It's for JavaScript-first libraries; one built with svelte-package already gets .d.ts files from svelte2tsx. A type it can't pin down falls back to any, and --strict says where. Carbon Components Svelte generates its types and API docs with it.
<!-- src/Button.svelte -->
<script>
/** @type {"button" | "submit" | "reset"} */
export let type = "button";
/** Set to `true` to use the primary variant */
export let primary = false;
</script>
<button {...$$restProps} {type} class:primary on:click>
<slot>Click me</slot>
</button>
// types/Button.svelte.d.ts, from `npx sveld` (imports left out)
type $RestProps = SvelteHTMLElements["button"];
type $Props = {
/**
* @default "button"
*/
type?: "button" | "submit" | "reset";
/**
* Set to `true` to use the primary variant
* @default false
*/
primary?: boolean;
children?: (this: void) => void;
[key: `data-${string}`]: unknown;
};
export type ButtonProps = Omit<$RestProps, keyof $Props> & $Props;
export default class Button extends SvelteComponentTyped<
ButtonProps,
{ click: WindowEventMap["click"] },
{ default: Record<string, never> }
> {}
An API change fails CI before it ships. Commit COMPONENT_API.json, and --check diffs each run against it:
$ npx sveld --check
sveld --check: 2 API changes detected against "COMPONENT_API.json".
Suggested semver bump: major.
Button
[BREAKING] prop "label" added (required)
[BREAKING] prop "primary" removed
It runs on Node 22 or later, or Bun, and parses Svelte 3, 4 and 5, runes included.
Quick start
npm i -D sveld
{
"svelte": "./src/index.js"
}
npx sveld # writes types/*.d.ts for what src/index.js exports
Exit status: 0 when done, 1 when the run found problems, 2 when it was called wrong or couldn't finish.
Common tasks
# Write the JSON and Markdown docs too
npx sveld --json --markdown
# Fail CI on a breaking API change against COMPONENT_API.json
npx sveld --check
# Fail CI where a prop fell back to `any` or a tag was dropped
npx sveld --strict
# Every .svelte file under the entry's directory, not just its exports
npx sveld --glob
# Svelte 5's `Component` type instead of a class
npx sveld --types-format=component
# Check the @example blocks against your TypeScript program
npx sveld --check-examples
With --format=json, the --check report and an exit-2 error print as JSON on stdout, each with a schemaVersion. The same options go in a sveld.config.js, or to the Vite plugin: sveld({ json: true }) in vite.config.ts.
From code
import { sveld } from "sveld";
const { document, diagnostics, exitCode, failures } = await sveld({
entry: "./src/index.js",
json: true,
});
document.components; // the same document `json: true` writes
Docs
- Options: every option and flag, the config file, the Vite plugin,
sveld(),sveld/browser, and requirements - JSDoc tags: how types are inferred, and every tag sveld reads
- Output: a worked example,
.d.tsformats, JSON and its schema, Markdown, and custom output - CI: exit codes,
--check,--strictand diagnostic codes, and@examplechecks - Troubleshooting: common problems, and the fix for each
- Playground: try it in the browser
관련 프로젝트 살펴보기
불러오는 중…