reactjstypescriptmeteortypescript2.0meteor-react

Module ''meteor/react-meteor-data'' has no exported member 'withTracker'


I am trying to migrate my Meteor-React project to TypeScript. I have a .tsx file:

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

class Header extends React.Component<any,any> {
...
}

export default withTracker(() => {
  return {
    ...
  };
})(Header);

But I am getting the error, even though the site renders correctly:

Module ''meteor/react-meteor-data'' has no exported member 'withTracker'.

Running versions:

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

Thank you for your help.


Solution

  • The react-meteor-data package does not contain type information. This repository contains types for the old createContainer, but the repo has not been updated with withTracker.

    I have solved this by including a .d.ts file somewhere in the project with the following declaration:

    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>;
    }