Code Monkey home page Code Monkey logo

Comments (5)

mrcrazylee avatar mrcrazylee commented on June 8, 2024 1

Are there any plans to add these type definitions?! I also really love this icon set, but it would even be more awesome with typing 😄

from react-feather.

brandonmp avatar brandonmp commented on June 8, 2024

@sgoll thanks for making these. quick question: why do you pass SVGElement to the generic SVGAttributes?

ie

interface Props extends SVGAttributes<SVGElement> {
  color?: string;
  size?: number;
}

I'm still learning TS and not super clear on generics in general, but i had typed it simply as React.SVGAttributes<T>, and it seemed to work equally well, so just wondering what SVGElement adds to the typing.

from react-feather.

sgoll avatar sgoll commented on June 8, 2024

@brandonmp SVGAttributes is defined in @types/react/index.d.ts as follows:

interface SVGAttributes<T> extends DOMAttributes<T> { ... }

DOMAttributes in turn uses T in all its event handler attributes to make sure that the events' target property has the correct type: that of the original element, in this case SVGElement.

Since react-feather always creates an SVG element for each icon, this should be typed statically, not itself as generic (because the user is not able to replace the <svg/> with anything else).

All in all, this becomes only relevant when one wants to attach custom event handlers to an icon, such as:

<Activity onClick={...} />

from react-feather.

carmelopullara avatar carmelopullara commented on June 8, 2024

Since I'm not familiar with TypeScript, if someone wants to update the build script to include type definitions, PRs are welcome!

from react-feather.

brandonmp avatar brandonmp commented on June 8, 2024

@sgoll ahhh that makes sense. thanks for explaining it

@carmelopullara I don't think it requires modding the build script--it should just require including an index.d.ts file in the project root (or maybe in dist?), but I will defer to someone more well-versed in TS than i am.

from react-feather.

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.