Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Add TypeScript example #4

Closed
ai opened this issue Dec 3, 2021 · 2 comments
Closed

Add TypeScript example #4

ai opened this issue Dec 3, 2021 · 2 comments

Comments

@ai
Copy link

ai commented Dec 3, 2021

Of course, *.svg files doesn’t have types.

We can improve user’s onboarding by adding some solution for TypeScript, since it is very widely used.

@trmcnvn trmcnvn closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2022
@vincerubinetti
Copy link

vincerubinetti commented Jan 8, 2023

How do I type the imports to get rid of this error:

Cannot find module '@/icons/play.svg?component' or its corresponding type declarations.

Normally I would do:

declare module "svg";

But that gets tripped up by the odd ?component. How do I account for that in my module declaration?

Related: microsoft/TypeScript#38638

@vincerubinetti
Copy link

vincerubinetti commented Jan 8, 2023

I think this is a solution:

declare module "*svg?component" {
  import { ComponentType, SvelteComponentTyped } from "svelte";
  const icon: ComponentType<SvelteComponentTyped>;
  export default icon;
}

Though this doesn't work for importing the component in Astro too, which I'm using.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants