zeromake / preact-animate

fork by https://github.com/react-component/animate
MIT License
7 stars 1 forks source link

Typings #2

Open jantimon opened 3 years ago

jantimon commented 3 years ago

Hey :)

is there any way to get typings for this library?

buzjuka commented 3 years ago

Hi, you can use this workaround

yourPath/types/preact-animate/index.d.ts
declare module 'preact-animate' {
  enum AnimateType {
    enter = 1,
    leave = 2,
    appear = 3,
    disappear = 4
  }

  interface IAnimateChildProps {
    key: string
    animation: object
    transitionName: string|object
    transitionEnter: boolean
    transitionAppear: boolean
    transitionLeave: boolean
    transitionDisappear: boolean
    displyShow: boolean
    children?: any[]
    isRender: boolean
    onEnter: (child: AnimateChild, done: () => void) => void
    onLeave: (child: AnimateChild, done: () => void) => void
    onAppear: (child: AnimateChild, done: () => void) => void
    onDisappear: (child: AnimateChild, done: () => void) => void
  }

  class AnimateChild extends preact.Component<IAnimateChildProps> {}

export interface IProps {
    children: preact.ComponentChildren
    component?: any
    componentProps?: object
    animation?: object
    transitionName?: string | object
    transitionEnter?: boolean
    transitionLeave?: boolean
    transitionAppear?: boolean
    transitionDisappear?: boolean
    exclusive?: boolean
    onBeforeEnter?: (child: AnimateChild) => any
    onEnter?: (child: AnimateChild, done: () => void) => void
    onAfterEnter?: (child: AnimateChild) => any
    onBeforeLeave?: (child: AnimateChild) => any
    onLeave?: (child: AnimateChild, done: () => void) => void
    onAfterLeave?: (child: AnimateChild) => any
    onBeforeAppear?: (child: AnimateChild) => void
    onAppear?: (child: AnimateChild, done: () => void) => void
    onAfterAppear?: (child: AnimateChild) => void
    onBeforeDisappear?: (child: AnimateChild) => void
    onDisappear?: (child: AnimateChild, done: () => void) => void
    onAfterDisappear?: (child: AnimateChild) => void
    onAfterCancelled?: (child: AnimateChild, status: AnimateType) => any
    showProp?: string
    disableShow?: boolean
    className?: string
    style?: string | object
    isRender?: boolean
  }

  export default class Animate extends preact.Component<IProps> {}
}
  1. add in tsconfing.json
    "compilerOptions": {
    ...,
    "typeRoots": ["node_modules/@types", "yourPath/types"]1
    }