JSPM

svelte-ts-preprocess

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 26
  • Score
    100M100P100Q37085F
  • License MIT

Typescript preprocessor for Svelte 3

Package Exports

  • svelte-ts-preprocess

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (svelte-ts-preprocess) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

!!! THIS PREPROCESSOR IS VERY EXPERIMENTAL !!!

svelte-ts-preprocess

Typescript type-checking preprocessor for Svelte 3.

Usage

Install with npm or yarn:

npm install --save-dev svelte-ts-preprocess

Then import the plugin to your bundler config. Rollup example below.

import svelte from 'rollup-plugin-svelte';
import ts from 'svelte-ts-preprocess';
...
export default {
    ...
    plugins: [
        svelte({
            ...
            preprocess: [
                ts()
            ]
        }),
        ...
    ]
};

Or use it with svelte-preprocess:

import svelte from 'rollup-plugin-svelte';
import ts from 'svelte-ts-preprocess';
import preprocess from 'svelte-preprocess';
...
export default {
    ...
    plugins: [
        svelte({
            ...
            preprocess: preprocess({
                transformers: { 
                    ts: ts().script
                },
                aliases: [
                    ['ts', 'typescript']
                ]
            })
        }),
        ...
    ]
};

Options

By default Typescript options will be retrieved from tsconfig.json but you also can pass config object directly to the preprocessor function. You should choose one of this variants to get it work.

Example

After preprocessor is setted up you'll be able to write Typescript code inside of component's script.

<script lang="ts">
    interface HTMLInputTarget {
        "target": HTMLInputElement;
    }

    export let num: number = 0;

    function handleChange(e: HTMLInputTarget) {
        num = e.target.value;
    }
</script>

<input on:change={handleChange} placeholper="Enter a number">

And will get type-checking warnings upon building process.

./src/App.svelte (9,2): Type 'string' is not assignable to type 'number'.

License

MIT