You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added support for TypeScript, Flow interfaces and Flow generic types (#348)
* Support parsing typescript with babel
* Process TypeScript annotations
* Support typescript and flow interfaces
* Add composes for unresolved interface extensions
* Move TypeScript output to tsType instead of flowType
* Add support for flow and typescript generic type parameters
* Support method parameters in TypeScript
* Support rest parameters in function signatures
* Bump recast
* Separate TS `this` parameters from arguments
* Code review comments
* Fix tests for latests babel parser and yarn lock
Copy file name to clipboardExpand all lines: README.md
+6-3Lines changed: 6 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -239,15 +239,15 @@ we are getting this output:
239
239
}
240
240
```
241
241
242
-
## Flow Type support
242
+
## Flow and TypeScript support
243
243
244
-
If you are using [flow][flow] then react-docgen can also extract the flow type annotations. As flow has a way more advanced and fine granular type system, the returned types from react-docgen are different in comparison when using `React.PropTypes`.
244
+
If you are using [flow][flow]or [typescript][typescript]then react-docgen can also extract the type annotations. As flow and typescript have way more advanced and fine granular type systems, the returned types from react-docgen are different in comparison when using `React.PropTypes`.
245
245
246
246
> **Note**: react-docgen will not be able to grab the type definition if the type is imported or declared in a different file.
247
247
248
248
### Example
249
249
250
-
For the following component
250
+
For the following component with Flow types
251
251
252
252
```js
253
253
importReact, { Component } from'react';
@@ -387,6 +387,7 @@ The structure of the JSON blob / JavaScript object is as follows:
387
387
["raw": string]
388
388
},
389
389
"flowType": <flowType>,
390
+
"tsType": <tsType>,
390
391
"required": boolean,
391
392
"description": string,
392
393
["defaultValue": {
@@ -406,9 +407,11 @@ The structure of the JSON blob / JavaScript object is as follows:
406
407
- `<typeName>`: The name of the type, which is usually corresponds to the function name in `React.PropTypes`. However, for types define with `oneOf`, we use `"enum"` and for `oneOfType` we use `"union"`. If a custom function is provided or the type cannot be resolved to anything of `React.PropTypes`, we use `"custom"`.
407
408
- `<typeValue>`: Some types accept parameters which define the type in more detail (such as `arrayOf`, `instanceOf`, `oneOf`, etc). Those are stored in `<typeValue>`. The data type of `<typeValue>` depends on the type definition.
408
409
- `<flowType>`: If using flow type this property contains the parsed flow type as can be seen in the table above.
410
+
- `<tsType>`: If using TypeScript type this property contains the parsed TypeScript type as can be seen in the table above.
0 commit comments