npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

svelte-global-typescript

v1.0.1

Published

Enable TypeScript mode by default in Svelte components.

Readme

svelte-global-typescript

Use TypeScript in Svelte components without writing lang="ts" everywhere.

svelte-global-typescript is a tiny Vite plugin and Svelte preprocessor. Put ts() before SvelteKit's Vite plugin for builds, and put the same ts() in Svelte config preprocessing when you want editor tooling to parse plain <script> blocks as TypeScript too.

It also supports .sv files, so it works neatly with svelte-sv-extension.

Install

pnpm add -D svelte-global-typescript

Setup

Add the plugin to vite.config.ts before sveltekit():

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

export default defineConfig({
	plugins: [ts(true), sveltekit()],
});

ts() is the same as ts(true). Use ts(false) when you want to keep the plugin installed but temporarily disabled.

The plugin is also available from its area export:

import { ts } from "svelte-global-typescript/vite";

Editor Setup

Vite plugins run during the build. Editors and the Svelte language server read Svelte config instead, so add the same ts() helper to svelte.config.js:

import { ts } from "svelte-global-typescript";

export default {
	preprocess: [ts()],
};

That is the part that removes the need for <script lang="ts"> in editor diagnostics. The Vite plugin and the preprocessor share the same transform.

With svelte-plugin-composer

When using svelte-plugin-composer, add ts() before kit(...):

import adapter from "@sveltejs/adapter-auto";
import { ts } from "svelte-global-typescript";
import { compose_config, kit } from "svelte-plugin-composer";

export default compose_config([ts(), kit({ adapter: adapter() })]);

Then keep Vite in external-config mode:

import { ts } from "svelte-global-typescript";
import { compose, kit } from "svelte-plugin-composer";
import { defineConfig } from "vite";

export default defineConfig({
	plugins: compose([ts(), kit()], {
		svelte_config: "external",
	}),
});

The composer may strip the plugin's pre priority, but it preserves the order you wrote, so ts() still runs before SvelteKit in the final plugin list. It also lets compose_config(...) place the same ts() preprocessor in svelte.config.js, which is the part editor tooling reads.

What It Does

These components compile with TypeScript mode enabled:

<script>
  let name: string = "world";
</script>

<h1>{name}</h1>
<p>{value as string}</p>

Under the hood, the plugin adds lang="ts" to Svelte script tags that do not already have a lang attribute. If a component has no script tag, it adds an empty TypeScript script so TS-only markup expressions work too.

Explicit language attributes are preserved:

<script lang="js">
  let name = "world";
</script>

That gives each file an escape hatch.

Limits

This enables Svelte's built-in TypeScript support, which covers type-only syntax such as annotations, interfaces, casts, and typed props.

TypeScript features that emit runtime JavaScript, such as enums, still need the usual Svelte preprocessing setup:

import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";

export default {
	preprocess: vitePreprocess({ script: true }),
};

For editor support, make sure ts() is present in svelte.config.js preprocessing as shown above. A Vite-only setup still builds, but the editor does not run Vite transforms before parsing a file.

.sv Files

The plugin transforms .svelte and .sv files. To make SvelteKit discover .sv route components, configure Svelte's extensions separately:

export default {
	extensions: [".svelte", ".sv"],
};