Giter Site home page Giter Site logo

Comments (8)

kreuzerk avatar kreuzerk commented on September 24, 2024

Hi @Jakob-em

Thanks a lot for the feature request. We already allow you to generate an Object of the types which you can use to iterate through. To generate this object you need to set the generateTypeObject flag to true.

The output will be something like this:

export type myIcons = 'expression_less' | 'full' | 'laughing' | 'smiling_face';

export const myIcons = {
  expression_less: 'expression_less' as myIcons,
  full: 'full' as myIcons,
  laughing: 'laughing' as myIcons,
  smiling_face: 'smiling_face' as myIcons
};

export interface MyIcon {
  name: myIcons;
  data: string;
}

from svg-to-ts.

Jakob-em avatar Jakob-em commented on September 24, 2024

Hi @kreuzerk,
Thanks for your quick answer. I know that the generation of a union type is currently possible, but the problem with union types is that you can not iterate over the possbile values. To solve this issue and allow for iteration over all icons I suggested to change the generation of the union type to be created via an immutable array. This would allow for both type safety, but also iterating the possible icons

from svg-to-ts.

kreuzerk avatar kreuzerk commented on September 24, 2024

Hi @Jakob-em. Yes, but you can iterate over the generated object by using Object.keys.

export const myIcons = {
  expression_less: 'expression_less' as myIcons,
  full: 'full' as myIcons,
  laughing: 'laughing' as myIcons,
  smiling_face: 'smiling_face' as myIcons
};

We first wanted to create an enum - here's what we discussed back then.

from svg-to-ts.

Jakob-em avatar Jakob-em commented on September 24, 2024

Ah yes your totally right, but this wouldn't work when using conversionType 'files' right? (Thats what i tried to use)

from svg-to-ts.

kreuzerk avatar kreuzerk commented on September 24, 2024

It also works for converstionType files. But you need to set the generateTypeObject flag to true.

from svg-to-ts.

kreuzerk avatar kreuzerk commented on September 24, 2024

Let me know if there are issues or if you need help

from svg-to-ts.

Jakob-em avatar Jakob-em commented on September 24, 2024

Now i get it. Yes this should work. Thanks for the quick help 👍

from svg-to-ts.

kreuzerk avatar kreuzerk commented on September 24, 2024

No worries. Glad to hear that it works. 👍

from svg-to-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.