我正在尝试将Meteor-React项目迁移到TypeScript。我有一个.tsx文件:
import { withTracker } from 'meteor/react-meteor-data';
class Header extends React.Component<any,any> {
...
}
export default withTracker(() => {
return {
...
};
})(Header);
但是我收到错误,即使网站呈现正确:
Module ''meteor/react-meteor-data'' has no exported member 'withTracker'.
正在运行的版本:
Local package version is up-to-date: babel-compiler@7.0.6
Local package version is up-to-date: babel-runtime@1.2.2
Local package version is up-to-date: barbatus:typescript@0.6.12
Local package version is up-to-date: barbatus:typescript-compiler@0.9.12
Local package version is up-to-date: barbatus:typescript-runtime@1.0.2
Local package version is up-to-date: ecmascript@0.10.6
Local package version is up-to-date: ecmascript-runtime@0.5.0
Local package version is up-to-date: ecmascript-runtime-client@0.6.2
Local package version is up-to-date: ecmascript-runtime-server@0.5.0
Local package version is up-to-date: meteor@1.8.6
Local package version is up-to-date: react-meteor-data@0.2.16
感谢您的帮助。
答案 0 :(得分:2)
react-meteor-data
包不包含类型信息。 This repository包含旧createContainer
的类型,但尚未使用withTracker
更新回购。
我通过在项目中的某处包含.d.ts
文件并使用以下声明解决了这个问题:
declare module 'meteor/react-meteor-data' {
import * as React from 'react';
type RMDComponentConstructor<P> = React.ComponentClass<P> | React.StatelessComponent<P>
export function withTracker<InP, D, OutP extends (InP & D)>(
options: (props: InP) => D | {getMeteorData: (props: InP) => D, pure?: boolean}):
(reactComponent: RMDComponentConstructor<OutP>) => RMDComponentConstructor<InP>;
}