Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) Add support for svelte-jsx.d.ts and svelte-native-jsx.d.ts to emitDts #1405

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/svelte2tsx/src/emitDts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { svelte2tsx } from './svelte2tsx';
export interface EmitDtsConfig {
declarationDir: string;
svelteShimsPath: string;
svelteJsxPath?: string;
svelteNativeJsxPath?: string;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is adding a [string] option for additional paths instead of just listing these out individually, and another alternative is emitDts just finding & reading these itself (I wasn't sure why it's structured this way right now). Another option is combining all of the declarations into one file.

Obviously you folks would know best, I just opened this PR to get the ball rolling.

libRoot?: string;
}

Expand Down Expand Up @@ -72,6 +74,14 @@ 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);
// Add the svelte.JSX namespace so TS can resolve users' references to it
if (config.svelteJsxPath) {
filenames.push(config.svelteJsxPath);
}
// Add the svelteNative.JSX namespace so TS can resolve users' references to it
if (config.svelteNativeJsxPath) {
filenames.push(config.svelteNativeJsxPath);
}

return {
options: {
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte2tsx/test/emitDts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ async function testEmitDts(sample: string) {
await emitDts({
declarationDir: 'package',
svelteShimsPath: require.resolve(join(process.cwd(), 'svelte-shims.d.ts')),
svelteJsxPath: require.resolve(join(process.cwd(), 'svelte-jsx.d.ts')),
svelteNativeJsxPath: require.resolve(join(process.cwd(), 'svelte-native-jsx.d.ts')),
...config,
libRoot: config.libRoot ? join(cwd, config.libRoot) : cwd
});
Expand Down