0

I'm gradually moving my current react project into typescript. While doing that, I've met some strange situation.

// MyComponent.js
import {someHoc} from 'recompose' // is typed by DefinitelyTyped.

class MyComponent extends React.Component {
  ...
}

const component = someHoc(options)(MyComponent)
export default component

When I imported MyComponent from a typed code, typescript check the Props of MyComponent and throw errors on type checking someHoc

  1. Why they check type from JS module? I think tsc should not check the type of exported component, cause it is written on JS

  2. How can I suppress this error without converting MyComponent to typescript?

FourwingsY
  • 669
  • 2
  • 7
  • 18
  • The problem lies in the fact that you are not exporting `MyComponent` but a HOC wrapped `component` here. Typescript is not checking the type of `MyComponent` but of the component returned by `someHoc(options)(MyComponent)` – Vijay Dev Mar 29 '18 at 07:56
  • Yeah, that's how to use hoc. So it could never be the problem i guess. But, does typescript checks returned class? not the code? – FourwingsY Mar 29 '18 at 14:32

0 Answers0