When it comes to Svelte, the final output is native JavaScript classes, which TypeScript can understand. However, before TypeScript can recognize Svelte components, they must first be compiled from their initial .html
form. This can lead to a 'cannot find module' error in TypeScript, even though the import works at runtime. Is there a way for TypeScript to better understand Svelte components?
One potential solution could involve creating type definitions for .html
modules that mimic the standard Svelte component interface. But ideally, using the actual output of the component class would provide the most accurate type information for each individual component.
It's worth noting that popular tools like Webpack or Rollup typically handle the compilation process for Svelte. It's unclear if these tools play a role in addressing this specific issue.
Update 1: Upon further investigation, it appears that plugins can be developed for TypeScript according to official documentation. However, the limitations of these plugins may hinder their usefulness in this context.
Update 2: Discussions have emerged regarding custom module loaders in TypeScript, as seen in threads here and here.