Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
feat: add support for symbol propType
Browse files Browse the repository at this point in the history
  • Loading branch information
KnisterPeter committed Nov 4, 2016
1 parent 71caffe commit c2a2542
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Create typescript definitions files (d.ts) from react components.

* ES6 and ES7 class syntax
* Most PropTypes
* any, array, bool, func, number, object, string, node, element, oneOfType, arrayOf
* any, array, bool, func, number, object, string, node, element, oneOfType, arrayOf, symbol
* required PropTypes
* instanceOf PropTypes (when using API and giving a resolve function)
* jsdoc
Expand All @@ -39,11 +39,19 @@ npm install -g react-to-typescript-definitions
### CLI

```sh
# Create a definition which exports a module named 'module-name'
cat <some/react/component.jsx> |react2dts --name module-name
Usage
$ react2dts [--module-name <name> | --top-level-module]

# Create a definition which exports top level definitions
cat <some/react/component.jsx> |react2dts --top-level-module
react2dts reads from stdin to process a file.

Options
--module-name, --name name of the module to create
--top-level-module if the created module should live in top-level

Examples
$ cat <some/react/component.jsx> |react2dts --module-name module-name

$ cat <some/react/component.jsx> |react2dts --top-level-module
```
### API
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export function get(astq: astqts.ASTQ, propertyAst: any, propTypesName: string|u
return getTypeDeclaration(dom.create.namedTypeReference('React.ReactNode'), !required);
case 'element':
return getTypeDeclaration(dom.create.namedTypeReference('React.ReactElement<any>'), !required);
case 'symbol':
return getTypeDeclaration(dom.create.typeof(dom.create.namedTypeReference('Symbol')), !required);
}

const [, complexTypeName, typeAst] = getComplexTypeName(astq, propertyAst, propTypesName);
Expand Down
1 change: 1 addition & 0 deletions tests/es6-class.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare module 'component' {
requiredAny: any;
requiredUnion: any[] | boolean;
requiredArrayOf: string[];
requiredSymbol: typeof Symbol;
}
export class Component extends React.Component<ComponentProps, any>{
}
Expand Down
1 change: 1 addition & 0 deletions tests/es6-class.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ Component.propTypes = {
React.PropTypes.bool
]).isRequired,
requiredArrayOf: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
requiredSymbol: React.PropTypes.symbol.isRequired,
};

0 comments on commit c2a2542

Please sign in to comment.