-
-
Notifications
You must be signed in to change notification settings - Fork 635
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
Inferno in tsx files #521
Comments
@isergey No, due to limitations in Typescript (for now), there's no way to tell it to use a custom JSX parser, as we create and handle JSX differently from the default React version. How the Inferno team have dealt with this, is to ensure JSX remains as is (not compiled by Typescript) and then to use Babel to compile the JSX to ES5/ES6. I hope that helps! |
FYI, there's Here's an example from my experiment: tsconfig.json:
Button.tsx: import * as createElement from 'inferno-create-element';
import * as Component from 'inferno-component';
class Button extends Component<{}, {}> {
render() {
return (
<button>It's a button!</button>
);
}
}
export default Button; This requires modified typings, though (#505 (comment)): node_modules/inferno/index.d.ts: declare module 'inferno-component' {
class Component<P, C> {
refs?: any;
state?: any;
props?: P;
context?: C;
_unmounted?: boolean;
constructor (props?: P, context?: C);
componentWillReact();
componentWillReceiveProps? (nextProps: P, nextContext: C): void;
forceUpdate (): void;
setState (v: Object, cb?: () => {}): boolean;
isPrototypeOf (v: Object): void;
}
export = Component;
namespace Component {}
}
declare module 'inferno-create-element' {
function createElement(component: any, props: any, ...children): any;
namespace createElement {}
export = createElement;
} |
Man the typescript guys do ship amazing features lately! I'm really impressed by them! @dchest would you love to take on a PR? Otherwise I can do it the following days. |
@marvinhagemeister I'd leave it to you, as I'm afraid I'm confused with all this type declaration stuff, need to learn it properly first ;) |
I'm happy to take a PR for these changes against |
Let's add this to the 1.0 post roadmap @Havunen @nightwolfz @lukeed @LukeSheard |
What is that JSX factory how does it know how to create vNodes from JSX? |
Just wondering because... We have our babel plugin that compiles JSX into createVNodes |
@osdevisnot perhaps, this is because the imports are incorrect? Check how they've done in my comment. |
@dchest unfortunately no. When I switch the import style to match your comment, the TS compiler spits out this error: |
hey, in case anyone stumbled here looking to get inferno working with rollup and typescript, I have a really simple setup started here: https://github.com/mjw56/inferno-ts-rollup improvements are welcome! maybe we could have some sort of a semi-official example somewhere? |
How to use Inferno with Typescript? Typescript compile to React.createElement(AnyComponent...). Is is possible tell to TS compile as Inferno.createElement(AnyComponent...)?
Thanks a lot!
The text was updated successfully, but these errors were encountered: