How do I create a typescript definition file (d.ts) for an existing redux connected (jsx)component?

喜夏-厌秋 提交于 2019-12-11 01:45:59

问题


I'm adding new components written in TypeScript(tsx) to an existing codebase consisting of vanilla ES6 react components(jsx). When importing the existing jsx-components into a tsx-component I'm adding type defintions for the jsx-components.

My issue is how do I add a type definition for a jsx-component that is connected to redux using connect

Say I have an existing jsx component:

class DateField extends React.Component {
...
}

function mapStateToProps(state) {
  return {
    locale: state.systemUser.language.langKey
  };
}

export default connect(mapStateToProps) (DateField);

How would a typedefintion look like for this component?

Note: without the connect I would write the typedefinition like:

import * as React from 'react';
import * as moment from "moment";

export type IonDateFieldChange = (value: string | Date | moment.Moment) => void;
export interface IDateFieldProps {
  value: string | Date | moment.Moment
  onChange?: IonDateFieldChange
  placeholder?: string
}
declare class DateField extends React.Component<IDateFieldProps,any> {}

来源:https://stackoverflow.com/questions/49508800/how-do-i-create-a-typescript-definition-file-d-ts-for-an-existing-redux-connec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!