https://github.com/0xtheprodev/babel-plugin-flow-generate-typedef
Babel Plugin to Generate Library Definition for Libraries and Modules
https://github.com/0xtheprodev/babel-plugin-flow-generate-typedef
Last synced: 5 months ago
JSON representation
Babel Plugin to Generate Library Definition for Libraries and Modules
- Host: GitHub
- URL: https://github.com/0xtheprodev/babel-plugin-flow-generate-typedef
- Owner: 0xTheProDev
- License: mit
- Created: 2020-06-27T05:41:38.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T15:14:23.000Z (over 3 years ago)
- Last Synced: 2025-06-12T22:13:48.631Z (about 1 year ago)
- Language: JavaScript
- Size: 598 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Features
### 1. Persist type information
All Type defintion (and interface as well) should persist on output code as an exported value.
**Better**: Add Treeshaking to remove unused type/interface information.
#### Input
```typescript
export type Person {
name: string,
age: number,
}
type Car {
regno: string,
speed: number,
}
```
#### Output
```typescript
export type Person {
name: string,
age: number,
}
export type Car {
regno: string,
speed: number,
}
```
### 2. Convert Function Defintion to Declaration
Convert exported function definitions to declarations while specifying input param types and output type.
#### Input
```typescript
export function addTwoNumber(a: number, b: number): number {
return a + b;
}
```
#### Output
```typescript
declare function addTwoNumber(a: number, b: number): number;
```
### 3. Convert Class Definition to Interface Declaration
Convert Classes to Interfaces iterating over `constructor` and/or caret expression, and, other public methods.
**Better**: Avoid publishing life-cycle methods for `React.Component` child.
#### Input
```typescript
export class DialogWidget extends React.Component {
componentDidMount() {
window.title = 'Home Page';
}
getCurrentTime(): number {
return Date.now();
}
render() {
return (
Hello World
);
}
}
```
#### Output
```typescript
export interface DialogWidget extends React.Component {
getCurrentTime(): number;
}
```