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

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

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;
}
```