Coder Social home page Coder Social logo

Comments (4)

jonfreedman avatar jonfreedman commented on July 17, 2024 1

Here's a starting point

declare module 'react-flag-icon-css' {
    import {PureComponent} from 'react';

    export interface Options {
        useCssModules: boolean;
    }

    export interface FlagIconProps {
        code: string;
        size?: 'lg' | '2x' | '3x' | '4x' | '5x';
        flip?: 'horizontal' | 'vertical';
        rotate?: 30 | 60 | 90 | 180 | 270;
        squared?: boolean;
        className?: string;
        styleName?: string;
    }

    export class FlagIcon extends PureComponent<FlagIconProps> {
    }

    export default function FlagIconFactory(react: any, opts?: Options): () => FlagIcon
}

Although as per the various issues around string literal types (e.g. microsoft/TypeScript#20271) you end up needing to write something like this

<FlagIcon code='eu' size={'lg' as 'lg'}/>

from react-flag-icon-css.

jonfreedman avatar jonfreedman commented on July 17, 2024 1

Types are now @ https://www.npmjs.com/package/@types/react-flag-icon-css

Please feel free to merge them back into the lib if appropriate

from react-flag-icon-css.

matteocng avatar matteocng commented on July 17, 2024

Hi @jonfreedman thanks for that! It is unfortunate that TypeScript has some issues around string literal types (Flow too), I don't know if we could make it typecheck computed props too, that would be pretty nice (size={someSize}). If you could make a PR please feel free to do so, personally I was looking into typescript-definition-tester to run a test suite, but there may be better or more standard ways. Then, after the tests worked (even without custom flags initially), the enum types could be generated like we do with generate:types for Flow.

from react-flag-icon-css.

matteocng avatar matteocng commented on July 17, 2024

Thanks again @jonfreedman, that is great! 👍

from react-flag-icon-css.

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.