Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSX type errors with tag of type StatelessComponent<P> (Inferno@6) #13

Closed
smcatala opened this issue Oct 30, 2018 · 4 comments
Closed
Labels

Comments

@smcatala
Copy link

smcatala commented Oct 30, 2018

import { StatelessComponent } from 'inferno'

function wrap <P extends { value?: number } = { value?: number}> (
  ChildComponent: StatelessComponent<P>
) {
  return function ParentComponent ({ value }: { value: number }) {
    return (
      <div>
        value: <ChildComponent value={value} />
      </div>
    )
  }
}

errors on <ChildComponent value={value} />:

[ts]
JSX element type 'InfernoNode' is not a constructor function for JSX elements.
  Type 'string' is not assignable to type 'ElementClass'.
[ts] JSX element class does not support attributes because it does not have a 'props' property.

new since Inferno@6

@smcatala
Copy link
Author

using ChildComponent: (props: P) => InfernoNode results in the same error [ts] JSX element type 'InfernoNode' is not a constructor function for JSX elements. Type 'string' is not assignable to type 'ElementClass'., whereas ChildComponent: (props: P) => VNode is OK.

replacing InfernoNode with VNode in the .d.ts type definition file for StatelessComponent solves the issue.

interface StatelessComponent<P = Refs<P>> {
    (props: P & Refs<P>, context?: any): VNode;
    defaultProps?: Partial<P>;
    defaultHooks?: Refs<P>;
}

TS/JSX does not seem to accept that InfernoNode may be a string:
declare type InfernoNode = InfernoChild | InfernoFragment | JSX.Element | string | number | boolean | null
any idea why ?

@Havunen
Copy link
Member

Havunen commented Nov 4, 2018

hmm, I'm not sure. StatelessComponent can return string / boolean / array too. It would be nice to allow them somehow

@Havunen Havunen added the bug label Nov 4, 2018
smcatala added a commit to ZenyWay/zenypass that referenced this issue Dec 30, 2018
@Havunen
Copy link
Member

Havunen commented Jul 24, 2019

Is this still an issue? Should those type changes be updated to Inferno core types? Can you do PR there to see if it works?

@smcatala
Copy link
Author

smcatala commented Jul 25, 2019

with the latest commit c4662f9 (based on inferno@^7.2, TS@^3.5.3), the above code now generates a new error, maybe linked to TS issue microsoft/TypeScript#28884.
however, since this is not linked to the Inferno type definitions anymore, let's close this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants