wix-incubator / react-templates

Light weight templates for react
https://wix.github.io/react-templates
MIT License
2.82k stars 207 forks source link

typescript type-checker #181

Open nippur72 opened 8 years ago

nippur72 commented 8 years ago

TypeScript 2.0 allows to annotate the this context for functions, so it would possible for react-templates to emit a render() function that is type checked versus the React.Component it will be attached to.

That allows TypeScript users to catch lot of errors that otherwise would be discovered only at run time.

From my early experiments: (notice the this: component argument)

declare function h(...a:any[]);
import _ = require('lodash');

// imports the type 
import component from './mycomponent';

var render = function(this: component) { 
   function scopeData8(this: component) {
      // ...
   }
   return h('div',{},scopeData8.apply(this, [])) 
};

export = render;