TypeScript Version: 2.0.3 / nightly (2.1.0-dev.201xxxxx)
I think we should add another type to the "jsx" option in tsconfig.json named "local". This would expect a "createElement" function to be in scope when rendering .tsx files.
I think this mode would allow VueJS + TSX to work better. Currently, the "preserve" option needs to be set and then another transformer (there is a babel transformer) needs to be used on the output file. I think the integration would be a lot simpler with that change and wouldn't require a second transpiler.
I also think this change would make it easier for future libraries since they won't have to register globals, but instead simply supply a function that matches the react/vue createElement syntax.
Here is how I expect it to work:
The following would compile properly
TSX file
import{style}from'typestyle';import{HelloComponent}from'./components'constappStyles=style({fontFamily: 'Avenir, Helvetica, Arial, sans-serif','-webkitFontSmoothing': 'antialiased','-mozOsxFontSmoothing': 'grayscale',textAlign: 'center',color: '#2c3e50',marginTop: 60,});exportclassAppComponent{name='app';components={Hello: HelloComponent};render(createElement){return(<divid="app"className={appStyles}><imgsrc="./assets/logo.png"/><hello></hello></div>);}}Output file
"use strict";consttypestyle_1=require("typestyle");constcomponents_1=require("./components");constappStyles=typestyle_1.style({fontFamily: 'Avenir, Helvetica, Arial, sans-serif','-webkitFontSmoothing': 'antialiased','-mozOsxFontSmoothing': 'grayscale',textAlign: 'center',color: '#2c3e50',marginTop: 60,});classAppComponent{constructor(){this.name='app';this.components={Hello: components_1.HelloComponent};}render(createElement){return(createElement("div",{id: "app",className: appStyles},createElement("img",{src: "./assets/logo.png"}),createElement("hello",null)));}}exports.AppComponent=AppComponent;And the following change (remove createElement from arguments) would cause a compile error:
render(){return(<divid="app"className={appStyles}><imgsrc="./assets/logo.png"/><hello></hello></div>);}Error message:
Christophers-MacBook-Pro:just-motion2 cwallis$ node ../typescript/built/local/tsc
src/App.tsx(19,18): error TS2304: Cannot find name 'createElement'.
src/App.tsx(20,18): error TS2304: Cannot find name 'createElement'.
src/App.tsx(21,18): error TS2304: Cannot find name 'createElement'.
I realize I have done this out of order. I decided to figure out how it could be done, and then saw the checklist while trying to put in a pull request. I have a commit to a local fork that has a working version of this: notoriousb1t@44ade7a. I have signed the CTA. I need to add some unit tests to that, but I am otherwise ready to submit a PR if this addition will be accepted.
TypeScript Version: 2.0.3 / nightly (2.1.0-dev.201xxxxx)
I think we should add another type to the "jsx" option in tsconfig.json named "local". This would expect a "createElement" function to be in scope when rendering .tsx files.
I think this mode would allow VueJS + TSX to work better. Currently, the "preserve" option needs to be set and then another transformer (there is a babel transformer) needs to be used on the output file. I think the integration would be a lot simpler with that change and wouldn't require a second transpiler.
I also think this change would make it easier for future libraries since they won't have to register globals, but instead simply supply a function that matches the react/vue createElement syntax.
Here is how I expect it to work:
The following would compile properly
TSX file
Output file
And the following change (remove createElement from arguments) would cause a compile error:
Error message:
I realize I have done this out of order. I decided to figure out how it could be done, and then saw the checklist while trying to put in a pull request. I have a commit to a local fork that has a working version of this: notoriousb1t@44ade7a. I have signed the CTA. I need to add some unit tests to that, but I am otherwise ready to submit a PR if this addition will be accepted.