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
- Host: GitHub
- URL: https://github.com/grncdr/ts-react-loader
- Owner: grncdr
- Created: 2017-11-27T11:19:41.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2017-11-27T11:40:40.000Z (over 8 years ago)
- Last Synced: 2025-04-06T11:03:21.854Z (11 months ago)
- Topics: prop-types, typescript, webpack-loader
- Language: TypeScript
- Homepage:
- Size: 26.4 KB
- Stars: 70
- Watchers: 6
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
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!