Skip to content

Difference between how Svelte and JS imports from node_modules are handled #1056

@dummdidumm

Description

@dummdidumm

Through #1048, I noticed there is a difference between how JS and Svelte files imported from node_modules are handled:

  • Imports from node_modules that have no accompanying type definition (d.ts file) are marked as any which errors on strict mode (no implicit any). This means TS does not attempt to aquire the type structure from the node_modules package and also does not type-check it
  • Svelte imports from node_modules are read and treated as a regular file inside the project. This means they don't need a accompanying type definition and their types are aquired, which can be good or bad depending on the quality of the Svelte file. Some libraries like svelte-loading-spinners take advantage of this and provide TS-versions of Svelte files as types, which is dangerous.

I think in the long run it would be best to align with the behavior of TypeScript here. This would probably a breaking change to some users which do deep imports of Svelte files within libraries which don't have a .svelte.d.ts next to them. I'm also not sure how to even achieve this as I thought this stuff is handled inside ts.resolveModuleName. As an intermediate step, we definetly need to stop type-checking stuff inside node_modules (also see #1100)
@jasonlyu123 thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions