https://github.com/svecosystem/strip-types
A type stripper for Svelte.
https://github.com/svecosystem/strip-types
javascript strip svelte svelte-typescript ts-to-js typescript
Last synced: about 1 month ago
JSON representation
A type stripper for Svelte.
- Host: GitHub
- URL: https://github.com/svecosystem/strip-types
- Owner: svecosystem
- License: mit
- Created: 2025-03-13T12:50:29.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-03-25T15:07:53.000Z (about 2 months ago)
- Last Synced: 2025-04-21T09:18:24.621Z (about 1 month ago)
- Topics: javascript, strip, svelte, svelte-typescript, ts-to-js, typescript
- Language: TypeScript
- Homepage: https://www.npm.im/@svecosystem/strip-types
- Size: 142 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @svecosystem/strip-types
[](https://npmjs.com/package/@svecosystem/strip-types)
[](https://npmjs.com/package/@svecosystem/strip-types)
[](https://github.com/svecosystem/strip-types/blob/main/LICENSE)
[](https://discord.gg/fdXy3Sk8Gq)A type stripper for Svelte.
```sh
pnpm install @svecosystem/strip-types
``````ts
import { strip } from '@svecosystem/strip-types';const ts = `
let value = $state<string>('');
`const js = strip(ts);
```**In**
```svelte
type Foo = number
let value = $state<Foo>('');
```
**Out**
```svelte
let value = $state('');
```
## Formatting
By default `@svecosystem/strip-types` will remove leading and trailing whitespace when removing nodes. This will result in an output that is correctly formatted (with a small performance penalty).
If you are doing your own formatting you can disable this behavior with the `format` option like so:
```ts
const js = strip(ts, { format: false });
```### Empty Script Tags
Empty script tags can be created as a side effect of removing types or because there was an empty script tag just to enable TypeScript for the template.
In any case they serve no use in the output code and will be removed by default. You can disable this behavior with the `removeEmptyScripts` option like so:
```ts
const js = strip(ts, { removeEmptyScripts: false });
```## Limitations
### Formatting
While `@svecosystem/strip-types` includes a `format` option it is not a formatter. It will do it's best to maintain the formatting of the original code when stripping types but it is still recommended to use your own formatter if possible.
### Unsupported Syntax
- ❌ Enums
```ts
enum Foo {
Bar
}
```
- ❌ Constructor Parameter Properties
```ts
class Foo {
// the access modifier (public) is not allowed
constructor(public bar) {}
}
```## Contributing
Install dependencies:
```sh
pnpm install
```Run tests:
```sh
pnpm test
```Add a changeset with your changes:
```sh
pnpm changeset
```Finally before you commit your changes run:
```sh
pnpm formatpnpm check
```### Tests
If you are contributing please make sure to include tests.
All the test cases can be found under `./tests/cases`.
Each case is a folder with 2 files a `ts.svelte` and a `js.svelte`. `js.svelte` should be the stripped version of the `ts.svelte`. If you don't provide `js.svelte` then `vitest` will expect `strip` to error.
**Example test case**
```
tests
└── cases
├──
│ ├── js.svelte
│ └── ts.svelte
└── ...
```## License
Published under the [MIT](https://github.com/svecosystem/strip-types/blob/main/LICENSE) license.
Built by [Aidan Bleser](https://github.com/ieedan) and [community](https://github.com/svecosystem/strip-types/graphs/contributors).
![]()
## Community
Join the Discord server to ask questions, find collaborators, or just say hi!