在TypeScript中将箭头函数声明为return

时间:2018-05-02 12:12:22

标签: javascript typescript meteor return-value arrow-functions

我想为导出ReactMeteorData.jsxreact-meteor-data.jsx编写一个TypeScript声明:

export default function connect(options) {
  let expandedOptions = options;
  if (typeof options === 'function') {
    expandedOptions = {
      getMeteorData: options,
    };
  }

  const { getMeteorData, pure = true } = expandedOptions;

  const BaseComponent = pure ? ReactPureComponent : ReactComponent;
  return (WrappedComponent) => (
    class ReactMeteorDataComponent extends BaseComponent {
      ...
    }
  );
}

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/145223-compare-2-columns-in-different-sheets-and-copy-entire-rows-into-new-sheets重新包装为withTracker:

export { default as withTracker } from './ReactMeteorData.jsx';

我可以简单地将返回值声明为Function:

declare module 'meteor/react-meteor-data' {
  import * as React from 'react';    
  export function withTracker(func: () => {}): Function;

  ...
}

如何声明哪些参数并返回Function创建而无需更改origin包中的内容?所以我想做点什么:

export function withTracker(func: () => {}): (React.Component) => { React.Component };

代码的使用方式如下:

import * as React from 'react';
import { withTracker } from 'meteor/react-meteor-data';

class Header extends React.Component<any,any> {
  render() {
    return "test";
  }
}

export default withTracker(() => {
  return { user: 1 };
})(Header);

谢谢!

1 个答案:

答案 0 :(得分:0)

您描述的类型可以这样写:

Flowable

(c: React.Component) => React.Component 部分:

declare module