Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andrelmlins/svelte-dts

Typescript declaration generator for svelte with typescript
https://github.com/andrelmlins/svelte-dts

cli declaration-typescript generator rollup svelte transpiler typscript

Last synced: about 2 hours ago
JSON representation

Typescript declaration generator for svelte with typescript

Awesome Lists containing this project

README

        

# Svelte dts

[![npm version](https://badge.fury.io/js/svelte-dts.svg)](https://www.npmjs.com/package/svelte-dts) • [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/andrelmlins/svelte-dts/blob/master/LICENSE) • [![Node.js CI](https://github.com/andrelmlins/svelte-dts/workflows/Node.js%20CI/badge.svg)](https://github.com/andrelmlins/svelte-dts/actions?query=workflow%3A%22Node.js+CI%22)

Typescript declaration generator for svelte with typescript. Create the declaration files for your library and project. These are the main characteristics of this library:

✨ CLI(Command-line interface)


✨ Rollup plugin


✨ Svelte and typescript files

## How it works?

The `svelte-dts` interpret the properties, events and slot properties in the svelte code, using typescript and svelte compiler. The `svelte-dts` too interpret typescript and declaration typescript code, and create default declarations for javascript code.

Observe the code of the `click-counter-button` library that has the `ClickCounterButton` component:

```html

import { createEventDispatcher } from 'svelte';

export let initialNumber: number = 0;

let dispatch = createEventDispatcher<{ change: number }>();
let number = initialNumber;

$: dispatch('change', number);

(number += 1)}>Cliques: {number}
```

The result is the generated typescript declarations. Please note below:

```ts
import { SvelteComponentTyped } from 'svelte';

declare module 'click-counter-button' {
interface ClickCounterButtonProps {
initialNumber: number;
}

class ClickCounterButton extends SvelteComponentTyped }, {}> {}

export default ClickCounterButton;
}
```

## Installation

```
npm i svelte-dts
// OR
yarn add svelte-dts
```

## Using with rollup

```js
import typescript from '@rollup/plugin-typescript';
import svelte from 'rollup-plugin-svelte';
import autoPreprocess from 'svelte-preprocess';
import svelteDts from 'svelte-dts';

export default [
{
input: 'src/lib/App.svelte',
external: ['svelte/internal'],
plugins: [svelteDts(), svelte({ preprocess: autoPreprocess() }), typescript()],
},
];
```

### Options

| Option | Type | Description | Default |
| ------------ | ---------- | ------------------------ | ------------------------ |
| `output` | `string` | Declarations output file | The value of `pkg.types` |
| `extensions` | `string[]` | Valid Extensions | .svelte, .ts, .js |

## Using with cli

```sh
svelte-dts -i src/index.ts -o dist/index.d.ts
```

### Options

| Option | Alias | Description |
| -------------------------------------- | --------------- | ------------------------ |
| --input [input] | -i | App input file |
| --output [output] | -o | Declarations output file |
| --extensions [extensions] | -e | Valid Extensions |

## NPM Statistics

Download stats for this NPM package

[![NPM](https://nodei.co/npm/svelte-dts.png)](https://nodei.co/npm/svelte-dts/)

## License

Svelte dts is open source software [licensed as MIT](https://github.com/andrelmlins/svelte-dts/blob/master/LICENSE).