From 10147c3a00692b52c4c74b54fc6ce6ba9252b7fc Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 14 Mar 2022 15:56:24 +0100 Subject: [PATCH] (feat) make it possible to pass additional file paths to emitDts Needed when someone uses the svelte.JSX typings. Closes #1405 --- packages/svelte2tsx/index.d.ts | 5 +++++ packages/svelte2tsx/src/emitDts.ts | 2 ++ 2 files changed, 7 insertions(+) diff --git a/packages/svelte2tsx/index.d.ts b/packages/svelte2tsx/index.d.ts index 13b1b46ed..c97db72c7 100644 --- a/packages/svelte2tsx/index.d.ts +++ b/packages/svelte2tsx/index.d.ts @@ -78,6 +78,11 @@ export interface EmitDtsConfig { * Example: `require.resolve('svelte2tsx/svelte-shims.d.ts')` */ svelteShimsPath: string; + /** + * Additional file paths that need to be present when doing the dts emit. + * Example: `[require.resolve('svelte2tsx/svelte-jsx.d.ts')]` for the Svelte HTML ambient type definitions + */ + additionalPaths?: string[]; /** * If you want to emit types only for part of your project, * then set this to the folder for which the types should be emitted. diff --git a/packages/svelte2tsx/src/emitDts.ts b/packages/svelte2tsx/src/emitDts.ts index bf092b1eb..6ddcecdfb 100644 --- a/packages/svelte2tsx/src/emitDts.ts +++ b/packages/svelte2tsx/src/emitDts.ts @@ -5,6 +5,7 @@ import { svelte2tsx } from './svelte2tsx'; export interface EmitDtsConfig { declarationDir: string; svelteShimsPath: string; + additionalPaths?: string[]; libRoot?: string; } @@ -72,6 +73,7 @@ function loadTsconfig(config: EmitDtsConfig, svelteMap: SvelteMap) { // Add ambient functions so TS knows how to resolve its invocations in the // code output of svelte2tsx. filenames.push(config.svelteShimsPath); + filenames.push(...(config.additionalPaths || [])); return { options: {