Installation

Install svelte-global-typescript for Vite builds and Svelte editor tooling.

Install svelte-global-typescript as a development dependency.

deno add --dev npm:svelte-global-typescript

Create one plugin instance, put it before SvelteKit in the Vite plugin list, and give the same instance to Svelte's preprocessors.

vite.config.ts
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
import { ts } from "svelte-global-typescript";

const global_typescript = ts();

export default defineConfig({
	plugins: [
		global_typescript,
		sveltekit({
			preprocess: [global_typescript],
		}),
	],
});

Vite uses the plugin transform during builds. SvelteKit and editor tooling use the preprocessor, so passing the same value through preprocess keeps both paths consistent without a separate Svelte config file.

ts() and ts(true) are equivalent. Use ts(false) to leave the Vite plugin installed while disabling component transforms.

On this page