benflap / tabler-icons-svelte

A library of SVG Svelte components for Tabler Icons.
MIT License
62 stars 7 forks source link

typescript support #6

Closed jmsunseri closed 3 years ago

jmsunseri commented 3 years ago

getting a bunch of errors running svelte-check

Hint: Could not find a declaration file for module 'tabler-icons-svelte'. 'sveltail/node_modules/tabler-icons-svelte/dist/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/tabler-icons-svelte` if it exists or add a new declaration (.d.ts) file containing `declare module 'tabler-icons-svelte';` (ts)
  import Markup from './Markup.svelte';
  import { BrandGithub, BrandTwitter } from 'tabler-icons-svelte';
</script>
benflap commented 3 years ago

I don’t know typescript. It looks like it needs a .d.ts file.

Do you think something like this would work in an index.d.ts:

export const componentName: any;

If I would create a line like that for every component.

benflap commented 3 years ago

Do you think something like this would work in an index.d.ts:

export const componentName: any;

It does work, but I would like to do better.

I've found a SvelteComponentTyped class in svelte. I just need to figure out how to give my icons that type. I’ve tried:

import { SvelteComponentTyped } from "svelte";
export class TablerIconComponent extends SvelteComponentTyped<{
    color?: string;
    size?: string | number;
    strokeWidth?: string | number;
}> {}

export const TwoFA: TablerIconComponent;
export const ThreeDCubeSphere: TablerIconComponent;
export const AB: TablerIconComponent;

When I run svelte-check on a test project I get this error:

Error: JSX element type 'CurrencyBitcoin' does not have any construct or call signatures. (ts)
jmsunseri commented 3 years ago

do you have to implement a constructor for TablerIconComponent?

benflap commented 3 years ago

v1.6.0 has been released and has an index.d.ts file. svelte-check no longer throws errors. Thanks for submitting this issue🙌