svg-icon icon indicating copy to clipboard operation
svg-icon copied to clipboard

Strictly-type generated files

Open csutorasr opened this issue 3 years ago • 2 comments

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

Icon types are not generated.

Expected behavior

Having the ability to get the names from the objects.

Minimal reproduction of the problem with instructions

const icons = [app1Icon, app2Icon];

type IconNames = (typeof icons[number])['name'];

IconNames is a string instead of array of const strings ('icon1' | 'icon2').

What is the motivation / use case for changing the behavior?

Using a wrapper component you can strictly type the icons. This means intellisense help, also.

To achieve this you need to wrap the original component.

Solution:

Strictly-type the name in the generated files:

const icon: {data: string; name: 'icontype'} = {
  data: '...',
  name: 'icontype',
}

csutorasr avatar Apr 07 '22 12:04 csutorasr

Suggested changes:

Add the type to the generated AST. https://github.com/ngneat/svg-icon/blob/4ac9f23016d7b40d57c90a9879ff3cc3fc07c267/svg-generator/ast.ts#L14

Add documentation to the Readme.MD how to add strictly typed components.

csutorasr avatar Apr 07 '22 12:04 csutorasr

You're welcome to submit a PR

NetanelBasal avatar Apr 07 '22 14:04 NetanelBasal

The keys now fully typed in v5 using the generator

NetanelBasal avatar Nov 03 '22 15:11 NetanelBasal