title: Can TypeScript understand Svelte components?
body: <p>Svelte ultimately outputs native JavaScript classes. So, TypeScript could understand these. However, Svelte components have to first be compiled from their initial <code>.html</code> form. Until then, understandably, TypeScript by default does not understand them in their initial form. So, it reports a 'cannot find module' error, even though at runtime the import is successful. Is there any way to make TypeScript understand them?</p>
  
  <p>One workaround would be to provide type definitions for <code>.html</code> modules, approximating the standard Svelte component interface. However, it would be much more desirable to simply use the real component class output itself for each individual component, yielding the most accurate type information.</p>
  
  <p>As an aside, I have not mentioned tools like Webpack or Rollup which perform the compilation step for Svelte normally. I do not know whether these tools would be relevant to this question.</p>
  
  <p><strong>Update 1:</strong> I've looked a little further into TypeScript and it <a href="https://github.com/Microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin" rel="noreferrer">seems that plugins can be created for it</a>. However, they seem limited, so may not be useful.</p>
  
  <p><strong>Update 2:</strong> There has also been some talk (<a href="https://github.com/Microsoft/TypeScript/issues/11610" rel="noreferrer">here</a> and <a href="https://github.com/Microsoft/TypeScript/issues/3136" rel="noreferrer">here</a>) about custom module loaders in TypeScript.</p>