Giter VIP home page Giter VIP logo

Comments (8)

giwiro avatar giwiro commented on August 10, 2024 4

I don't know if it helps but I made one for my project and it works for me.

declare module 'rodal' {
  import {MouseEventHandler, ReactNode} from 'react';

  type RodalProps = {
    children?: ReactNode;
    width?: number;
    height?: number;
    measure?: string;
    visible?: boolean;
    showMask?: boolean;
    closeOnEsc?: boolean;
    closeMaskOnClick?: boolean;
    showCloseButton?: boolean;
    animation?: string;
    enterAnimation?: string;
    leaveAnimation?: string;
    duration?: number;
    className?: string;
    customStyles?: {[key: string]: any};
    customMaskStyles?: {[key: string]: any};
    onClose?: MouseEventHandler<HTMLSpanElement>;
    onAnimationEnd?: () => never;
  };

  const Rodal = (_: RodalProps): JSX.Element => {};
  export = Rodal;
}

from rodal.

chenjiahan avatar chenjiahan commented on August 10, 2024 2

I sent a PR #72 for this matter.

Thanks for you contribution! This change has been released in v2.1.0

from rodal.

dansmog avatar dansmog commented on August 10, 2024 1

How do you make use of this? where do you save it?

from rodal.

giwiro avatar giwiro commented on August 10, 2024 1

How do you make use of this? where do you save it?

In order to use custom types you will need to import it through typescript. To do so, add the path to your custom types into the tsconfig.json.
For example if I got the following folder structure (included the custom-types folder):

project/
├── src/
├── custom-types/
    ├── rodal/
    │     └── index.d.ts.        <-- this is where the "decla module 'rodal'" file should be saved
    └── some-other-module/
          └── index.d.ts

In order to add the folder into typescript is adding it to the include key.

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src",
    "custom-types/**/*"
  ]
}

from rodal.

JackMcBride98 avatar JackMcBride98 commented on August 10, 2024

Make a PR for this :) it helped me out a lot. Although my linter did not like the return type (so I just ignored it for that line)

from rodal.

Verrok avatar Verrok commented on August 10, 2024
declare module 'rodal' {
  import {MouseEventHandler, ReactNode} from 'react';

  type RodalProps = {
    children?: ReactNode;
    width?: number;
    height?: number;
    measure?: string;
    visible?: boolean;
    showMask?: boolean;
    closeOnEsc?: boolean;
    closeMaskOnClick?: boolean;
    showCloseButton?: boolean;
    animation?: string;
    enterAnimation?: string;
    leaveAnimation?: string;
    duration?: number;
    className?: string;
    customStyles?: {[key: string]: any};
    customMaskStyles?: {[key: string]: any};
    onClose?: MouseEventHandler<HTMLSpanElement>;
    onAnimationEnd?: () => never;
  };

  const Rodal = (_: RodalProps): JSX.Element => {};
  export = Rodal;
}

thanks a lot

from rodal.

giwiro avatar giwiro commented on August 10, 2024

Now that I'm using nextjs I changed it a little bit:

declare module 'rodal' {
  import {MouseEventHandler, JSX, PropsWithChildren} from 'react';

  type RodalProps = PropsWithChildren & {
    width?: number;
    height?: number;
    measure?: string;
    visible?: boolean;
    showMask?: boolean;
    closeOnEsc?: boolean;
    closeMaskOnClick?: boolean;
    showCloseButton?: boolean;
    animation?: string;
    enterAnimation?: string;
    leaveAnimation?: string;
    duration?: number;
    className?: string;
    customStyles?: Record<string, any>;
    customMaskStyles?: Record<string, any>;
    onClose?: MouseEventHandler<HTMLSpanElement>;
    onAnimationEnd?: () => never;
  };

  function Rodal(_: RodalProps): JSX.Element;
  export = Rodal;
}

and in the tsconfig.json:

{
  "compilerOptions": {
    "typeRoots": [
      "custom-types",
      "node_modules/@types"
    ],
}

from rodal.

giwiro avatar giwiro commented on August 10, 2024

I sent a PR #72 for this matter.

from rodal.

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.