react组件库添加typescript类型提示 为react组件库添加typescript类型提示的方法
all2005 人气:0以我自己的组件react-better-countdown
为例,
首先在package.json
里面添加types: types/index.d.ts
,
,
然后文件目录上添加对应文件夹和文件,
最后是index.d.ts
文件的编写,具体看代码:
import * as React from 'react'; interface CountdownProps { count?: number; dayText?: string | React.ReactElement; hourText?: string | React.ReactElement; minuteText?: string | React.ReactElement; secondText?: string | React.ReactElement; callback?: Function; className?: string; style?: React.CSSProperties; rest?: any } interface CountdownState { count?: number; } declare module 'react-better-countdown' { export default class Countdown extends React.Component<CountdownProps, CountdownState> { state: CountdownState; timer: null | number; tick: () => void; componentDidMount(): void; componentDidUpdate(prevProps: CountdownProps): void; componentWillUnmount(): void; render: () => React.ReactElement; } }
更多详细代码看仓库:https://github.com/leeseean/react-better-countdown顺便求个Star!
加载全部内容