Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-ts-preprocess

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-ts-preprocess

Typescript preprocessor for Svelte 3

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14
decreased by-30%
Maintainers
1
Weekly downloads
 
Created
Source

!!! 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

Keywords

FAQs

Package last updated on 12 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc