Skip to content

Repository files navigation

ts-react-loader

Warning this code is proof-of-concept quality at best! If you find the idea compelling and would like to contribute to making it something reliably shippable, say hi.

What it does

Given a file like this:

import*asReactfrom"react";interfaceProps{foo: string;}classFooComponentextendsReact.Component<Props>{context: {store: {dispatch: (action: any)=>any;};};render(){return<strong>Yourfoo is: {this.props.foo}</strong>;}}

This loader will emit new TypeScript with prop & context types added:

import*asReactfrom"react";import*asPropTypesfrom"prop-types";interfaceProps{foo: string;}classFooComponentextendsReact.Component<Props>{staticpropTypes={foo: PropTypes.string.isRequired};staticcontextTypes={store: PropTypes.shape({dispatch: PropTypes.func.isRequired}).isRequired};context: {store: {dispatch: Function;};};render(){return<strong>Yourfoo is: {this.props.foo}</strong>;}}

Look ma! no repetition!

About

Automatic prop-types from TypeScript types

Topics

Resources

Stars

73 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages