An open API service indexing awesome lists of open source software.

https://github.com/grncdr/ts-react-loader

Automatic prop-types from TypeScript types
https://github.com/grncdr/ts-react-loader

prop-types typescript webpack-loader

Last synced: 8 months ago
JSON representation

Automatic prop-types from TypeScript types

Awesome Lists containing this project

README

          

# 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](https://github.com/grncdr/ts-react-loader/issues/1).

## What it does

Given a file like this:

```typescript
import * as React from "react";

interface Props {
foo: string;
}
class FooComponent extends React.Component {
context: {
store: {
dispatch: (action: any) => any;
};
};

render() {
return Your foo is: {this.props.foo};
}
}
```

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

```typescript
import * as React from "react";
import * as PropTypes from "prop-types";

interface Props {
foo: string;
}

class FooComponent extends React.Component {
static propTypes = {
foo: PropTypes.string.isRequired
};

static contextTypes = {
store: PropTypes.shape({
dispatch: PropTypes.func.isRequired
}).isRequired
};

context: {
store: {
dispatch: Function;
};
};

render() {
return Your foo is: {this.props.foo};
}
}
```

Look ma! no repetition!