question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve types for "* .svelte" files from "* .svelte.d.ts" if they exist

See original GitHub issue

Is your feature request related to a problem? Please describe.

I want to publish some svelte modules initially written in typescript and preprocessed into “plain” *.svelte. Also I want to provide typings for those files. It is convenient to place *.svelte.d.ts files near original *.svelte file, but svelte-language-server ignores these definition files.

Describe the solution you’d like

For plain *.svelte file, which doesn’t have lang="ts", lang-server should use simple typescript node-module resolving rules as first attempt. It means that if *.svelte.d.ts file exists then it should be used.

Additional context

I made a sample project where we can ensure that two files are checked differently and manually typed *.svelte file is not properly checked. Just clone https://github.com/trash-and-fire/svelte-typings-demo and npm install && npm run validate.

Errors should be the same between usages of typed.svelte and manually-typed.svelte components.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dummdidummcommented, Mar 13, 2021

Standard TS only looks at the file ending and prioritizes d.ts over .js . I think it’s even technically impossible for TS to load both and then decide which one to use, because the internal program can only contain one definition for one file, not two. This means that it’s not possible for Svelte files to change this behavior by actually looking into the file and determine if it has TS or not. This means we got to decide if we either always prioritize .svelte (current state) or always prioritize .svelte.d.ts . Since this only would really occur in the library case, I’m inclined to always prioritize svelte.d.ts . @jasonlyu123 @tomblachut thoughts?

0reactions
dummdidummcommented, Mar 19, 2021

@firefish5000 FYI, you might be interested in this upcoming change

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript support in Svelte - Learn web development
In this article we took our to-do list application and ported it to TypeScript.
Read more >
Typescript: Exported members from Svelte modules cannot be ...
When using Typescript, exported properties from a component's context="module" script can be imported in another .svelte file, but cannot be ...
Read more >
Types • Docs • SvelteKit
Resolve a path to the name directory inside outDir , e.g. /path/to/.svelte-kit/my-adapter . ts. getClientDirectory(): string;.
Read more >
Integrating TypeScript with Svelte | CSS-Tricks
This post will focus on configuring TypeScript inside of Svelte templates. If you're new to Svelte, I'd urge you to check out the...
Read more >
Is it possible to retain prop type information when importing ...
I 'd be OK with a method of defining the component props in a third location and importing them from both the Svelte...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found