Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.

Keep other static class members, such as defaultProps #36

Merged
merged 5 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export function hasStaticModifier(classMember: ts.ClassElement) {
*/
export function isPropTypesMember(classMember: ts.ClassElement, sourceFile: ts.SourceFile) {
try {
return classMember.name !== undefined && classMember.name.getFullText(sourceFile) !== 'propTypes';
const name =
classMember.name !== undefined && classMember.name.kind === ts.SyntaxKind.Identifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use ts.IsIdentifier(classMember.name)

? classMember.name.escapedText
: null;
return name === 'propTypes';
} catch (e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class SomeComponent extends React.Component<{
foo: number;
}, {
bar: string;
}> {
static propTypes = { foo: React.PropTypes.string };
static defaultProps = { foo: 'bar' };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class SomeComponent extends React.Component<
{
foo: number,
},
{
bar: string,
},
> {
static defaultProps = { foo: 'bar' };
}