nivekcode/svg-to-ts

conversionType==='constants' never uses the interface

Closed this issue · 2 comments

The example output for the constants shows

export const myIconExpressionLess: MyIcon = {
  name: 'expression_less',
  data: `<svg xmlns="http://...`
};
export const myIconFull: MyIcon = {
  name: 'full',
  data: `<svg xmlns="http://www...`
};
// etc...

But the reality is that the interface is never used and the output looks like this

export const myIconExpressionLess: {
  name: 'expression_less',
  data: string
} = {
  name: 'expression_less',
  data: `<svg xmlns="http://...`
};
export const myIconFull: {
  name: 'full',
  data: string
} = {
  name: 'full',
  data: `<svg xmlns="http://www...`
};

Am I missing something? Tried combinations of different configurations, and finally looked at the code. The interface is never used. It this a bug?

Hi @pwarelis I just checked it locally and this is actually correct. So the interface is generated as a helper type for your functions. This means you can use it to implement a registry for example. Imagine you would want to implement a registerIconsfunction. In such a case you could use the MyIcon interface to type the function signature.

registerIcons(icons: MyIcon[]){}

A single icon on the other hand isn't typed with MyIcon because it's to generic. We type it with the actual name only instead of the whole icon name type.

But we should definitely update the docs.

@pwarelis I updated the docs. I hope the explanation above is understandable and its okay for you if I close this Issue.