# svelte2tsx

> Convert Svelte components to TSX for type checking

Latest version **0.7.61** (published 2026-08-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install svelte2tsx
pnpm add svelte2tsx
yarn add svelte2tsx
bun add svelte2tsx
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.7.61 |
| Published | 2026-08-13 |
| First published | 2019-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 826.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 1445 |
| Author | The Svelte Community |
| Maintainers | svelte-language-tools-deploy, dummdidumm, orta, halfnelson |
| Keywords | svelte, typescript |

## Links

- npm: https://www.npmjs.com/package/svelte2tsx
- Repository: https://github.com/sveltejs/language-tools.git#master
- Homepage: https://github.com/sveltejs/language-tools/tree/master/packages/svelte2tsx
- Issues: https://github.com/sveltejs/language-tools/issues
- npm.io page: https://npm.io/package/svelte2tsx

## Dependencies (2)

- [scule](https://npm.io/package/scule.md) ^1.3.0
- [dedent-js](https://npm.io/package/dedent-js.md) ^1.0.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.7.61 (latest) — 2026-08-13
- 0.7.60 — 2026-08-11
- 0.7.59 — 2026-07-27
- 0.7.58 — 2026-07-15
- 0.7.57 — 2026-06-23
- 0.7.56 — 2026-06-01
- 0.7.55 — 2026-05-05
- 0.7.54 — 2026-05-01
- 0.7.53 — 2026-03-31
- 0.7.52 — 2026-03-07
- 0.7.51 — 2026-02-20
- 0.7.50 — 2026-02-20
- 0.7.49 — 2026-02-18
- 0.7.48 — 2026-02-13
- 0.7.47 — 2026-01-31
- … 311 more at https://npm.io/package/svelte2tsx/versions

## README

# svelte2tsx

Converts [Svelte](https://svelte.dev) component source into TSX. The TSX can be type checked using the included `svelte-jsx.d.ts` and `svelte-shims.d.ts`.

_This project only converts svelte to tsx, type checking is left to consumers of this plugin such as language services_

```typescript
type SvelteCompiledToTsx = {
    code: string;
    map: import('magic-string').SourceMap;
};

export default function svelte2tsx(svelte: string): SvelteCompiledToTsx;
```

For example

Input.svelte

```svelte
<script>
    export let world = 'name';
</script>

<h1>hello {world}</h1>
```

will produce this ugly but type checkable TSX

```tsx
<></>;
function render() {
    let world = 'name';
    <>
        <h1>hello {world}</h1>
    </>;
    return { props: { world }, slots: {}, events: {} };
}

export default class _World_ extends __sveltets_2_createSvelte2TsxComponent(
    __sveltets_2_partial(__sveltets_2_with_any_event(render))
) {}
```

with a v3 SourceMap back to the original source.

For more examples of the transformations, see the `test/**/samples` folders

## Credits

-   [halfnelson](https://github.com/halfnelson) for creating `svelte2tsx`
-   [pushkine](https://github.com/pushkine) for creating the source mapping test infrastructure

---
_Source: https://npm.io/package/svelte2tsx · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
