Inferno: There seems to be a mistake in type definition of SFC and Provider

Created on 26 Dec 2018  Â·  4Comments  Â·  Source: infernojs/inferno

inferno @7.0.4
inferno-mobx @7.0.4

Hi.

There seems to be a mistake in type definition of SFC and Provider.

// SFC
const MyComponent: SFC = (props) => {
  return <div>{props.children}</div> // Error: Property 'children' does not exist on type 'Refs<{}>'.
}

render(
  <MyComponent />, // Error: JSX element type 'InfernoNode' is not a constructor function for JSX elements. Type 'string' is not assignable to type 'Element | null'
  document.getElementById("app")
)
// Provider(inferno-mobx)
render(
  <Provider store={store}> // Error: JSX element type 'Provider' is not a constructor function for JSX elements.
    <MyComponent />
  </Provider>,
  document.getElementById("app")
)

The type of SFC should be corrected like this.

export interface StatelessComponent<P = Refs<P>> {
  (props: P & Refs<P> & {children?: InfernoNode}, context?: any): InfernoElement<any> | null;
  defaultProps?: Partial<P>;
  defaultHooks?: Refs<P>;
}

ref: https://github.com/infernojs/inferno/blob/master/packages/inferno/src/core/types.ts#L157-L162

But I did not know how to fix Provider.

Thank you.

bug

All 4 comments

Hi @highhi

Thanks for reporting the issue, I will look into this

This is tricky issue, because you can actually return string/number/undefined from SFC as its perfectly valid code.

Then this would fail:

export interface StatelessComponent<P = Refs<P>> {
  (props: P & Refs<P> & {children?: InfernoNode}, context?: any): InfernoElement<any> | null;
  defaultProps?: Partial<P>;
  defaultHooks?: Refs<P>;
}

This should be fixed now, I added test case for provider too but I was not able to re-produce the error. Please re-open if you still encounter that error. 7.0.5 released

Thank you! :)
I confirmed that the issue was solved.

Was this page helpful?
0 / 5 - 0 ratings