Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript support #267

Open
vinicios-gomes opened this issue Aug 12, 2021 · 3 comments
Open

TypeScript support #267

vinicios-gomes opened this issue Aug 12, 2021 · 3 comments

Comments

@vinicios-gomes
Copy link

It would be very beneficial to add TypeScript support via a declaration file. I'm currently working on a TypeScript-based Vue.js application. Personally, I feel much more comfortable with TS than with simple JS and I believe I can also support other application developers when they think about using this shared component library.

@susnux
Copy link
Contributor

susnux commented Dec 15, 2022

I think you can add something like this to your project in a global.d.ts:

declare module 'vue-material-design-icons/*.vue' {
	import type { DefineComponent } from 'vue'

	const IconVue : DefineComponent<
		{
			/// `size` defaults to 24
			size: number,
			/// `fillColor` defaults to 'currentColor'
			fillColor: string,
			title?: string,
		}>
	export default IconVue
}

Should work with vue 2.7 and vue 3

@Howard-Lam-UnitedVanning
Copy link

Howard-Lam-UnitedVanning commented Jul 3, 2023

@susnux I get the following error with your solution in the template
Argument of type '{}' is not assignable to parameter of type '{ readonly size: number; readonly fillColor: string; readonly title?: string | undefined; style?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ... 8 more ...; class?: unknown; } & Record<...>'.
Type '{}' is missing the following properties from type '{ readonly size: number; readonly fillColor: string; readonly title?: string | undefined; style?: unknown; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ... 7 more ...; class?: unknown; }': size, fillColor

example : <ChevronUp />
and it shows on ChevronUp

@VanGorg
Copy link

VanGorg commented Jul 6, 2023

@Howard-Lam-UnitedVanning
I just faced the same problem and got it working by declaring size and fillcolor as optional. So the file contents are now

declare module 'vue-material-design-icons/*.vue' {
  import type { DefineComponent } from 'vue';

  const IconVue: DefineComponent<{
    /// `size` defaults to 24
    size?: number;
    /// `fillColor` defaults to 'currentColor'
    fillColor?: string;
    title?: string;
  }>;
  export default IconVue;
}

Calling this file 'global.d.ts' strangely didn't work. It only worked after I prefixed it with 'shims'; now it is called 'shims-vue-mat-icons.d.ts' and sits at project root. This way, things finally work out without errors.

Thanks for your suggestion, @susnux

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

No branches or pull requests

4 participants