Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit ad78092

Browse files
authored
Stop getting PropTypes from React (#4)
1 parent 1e2c28a commit ad78092

File tree

40 files changed

+196
-196
lines changed

40 files changed

+196
-196
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Transforms React code written in JavaScript to TypeScript.
1818
```jsx
1919
class MyComponent extends React.Component {
2020
static propTypes = {
21-
prop1: React.PropTypes.string.isRequired,
22-
prop2: React.PropTypes.number,
21+
prop1: PropTypes.string.isRequired,
22+
prop2: PropTypes.number,
2323
};
2424
constructor() {
2525
super();

src/helpers/build-prop-type-interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as ts from 'typescript';
44
* Build props interface from propTypes object
55
* @example
66
* {
7-
* foo: React.PropTypes.string.isRequired
7+
* foo: PropTypes.string.isRequired
88
* }
99
*
1010
* becomes
@@ -53,7 +53,7 @@ export function buildInterfaceFromPropTypeObjectLiteral(objectLiteral: ts.Object
5353
}
5454

5555
/**
56-
* Turns React.PropTypes.* into TypeScript type value
56+
* Turns PropTypes.* into TypeScript type value
5757
*
5858
* @param node React propTypes value
5959
*/

src/helpers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function isReactHeritageClause(clause: ts.HeritageClause) {
6363
/**
6464
* Return true if a statement is a React propType assignment statement
6565
* @example
66-
* SomeComponent.propTypes = { foo: React.PropTypes.string };
66+
* SomeComponent.propTypes = { foo: PropTypes.string };
6767
* @param statement
6868
*/
6969
export function isReactPropTypeAssignmentStatement(statement: ts.Statement): statement is ts.ExpressionStatement {

src/transforms/react-move-prop-types-to-class-transform.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ export type Factory = ts.TransformerFactory<ts.SourceFile>;
1515
* @example
1616
* Before:
1717
* class SomeComponent extends React.Component<{foo: number;}, {bar: string;}> {}
18-
* SomeComponent.propTypes = { foo: React.PropTypes.string }
18+
* SomeComponent.propTypes = { foo: PropTypes.string }
1919
*
2020
* After
2121
* class SomeComponent extends React.Component<{foo: number;}, {bar: string;}> {
22-
* static propTypes = { foo: React.PropTypes.string }
22+
* static propTypes = { foo: PropTypes.string }
2323
* }
2424
*
2525
* @todo
2626
* This is not supporting multiple statements for a single class yet
2727
* ```
2828
* class SomeComponent extends React.Component<{foo: number;}, {bar: string;}> {}
29-
* SomeComponent.propTypes = { foo: React.PropTypes.string }
30-
* SomeComponent.propTypes.bar = React.PropTypes.number;
29+
* SomeComponent.propTypes = { foo: PropTypes.string }
30+
* SomeComponent.propTypes.bar = PropTypes.number;
3131
* ```
3232
*/
3333
export function reactMovePropTypesToClassTransformFactoryFactory(typeChecker: ts.TypeChecker): Factory {

src/transforms/react-remove-prop-types-assignment-transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type Factory = ts.TransformerFactory<ts.SourceFile>;
1010
* @example
1111
* Before:
1212
* class SomeComponent extends React.Component<{foo: number;}, {bar: string;}> {}
13-
* SomeComponent.propTypes = { foo: React.PropTypes.string }
13+
* SomeComponent.propTypes = { foo: PropTypes.string }
1414
*
1515
* After
1616
* class SomeComponent extends React.Component<{foo: number;}, {bar: string;}> {}

src/transforms/react-remove-static-prop-types-member-transform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type Factory = ts.TransformerFactory<ts.SourceFile>;
1111
* Before:
1212
* class SomeComponent extends React.Component<{foo: number;}, {bar: string;}> {
1313
* static propTypes = {
14-
* foo: React.PropTypes.number.isRequired,
14+
* foo: PropTypes.number.isRequired,
1515
* }
1616
* }
1717
*

src/transforms/react-stateless-function-make-props-transform.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type Factory = ts.TransformerFactory<ts.SourceFile>;
1717
* // const Hello = ({ message }) => <div>hello {message}</div>
1818
*
1919
* Hello.propTypes = {
20-
* message: React.PropTypes.string,
20+
* message: PropTypes.string,
2121
* }
2222
*
2323
* After:
@@ -30,7 +30,7 @@ export type Factory = ts.TransformerFactory<ts.SourceFile>;
3030
* }
3131
*
3232
* Hello.propTypes = {
33-
* message: React.PropTypes.string,
33+
* message: PropTypes.string,
3434
* }
3535
*/
3636
export function reactStatelessFunctionMakePropsTransformFactoryFactory(typeChecker: ts.TypeChecker): Factory {

test/end-to-end/initial-state-and-proprypes-and-set-state/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export default class MyComponent extends React.Component {
1111
}
1212

1313
MyComponent.propTypes = {
14-
baz: React.PropTypes.string.isRequired,
14+
baz: PropTypes.string.isRequired,
1515
}

test/end-to-end/initial-state-and-proprypes/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export default class MyComponent extends React.Component {
88
}
99

1010
MyComponent.propTypes = {
11-
baz: React.PropTypes.string.isRequired
11+
baz: PropTypes.string.isRequired
1212
}

test/end-to-end/multiple-components/input.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const Hey = ({ name }) => {
77
}
88

99
Hey.propTypes = {
10-
message: React.PropTypes.string,
10+
message: PropTypes.string,
1111
}
1212

1313
Hello.propTypes = {
14-
message: React.PropTypes.string,
14+
message: PropTypes.string,
1515
}
1616

1717
export default class MyComponent extends React.Component {
@@ -26,7 +26,7 @@ export default class MyComponent extends React.Component {
2626

2727
export class AnotherComponent extends React.Component {
2828
static propTypes = {
29-
foo: React.PropTypes.string.isRequired,
29+
foo: PropTypes.string.isRequired,
3030
};
3131
render() {
3232
return <div />;

test/end-to-end/stateless-arrow-function/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ const Hello = ({ message }) => {
33
};
44

55
Hello.propTypes = {
6-
message: React.PropTypes.string,
6+
message: PropTypes.string,
77
}

test/end-to-end/stateless-function/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ export function Hello({ message }) {
33
}
44

55
Hello.propTypes = {
6-
message: React.PropTypes.string,
6+
message: PropTypes.string,
77
}

test/react-js-make-props-and-state-transform/multiple-components/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class MyComponent extends React.Component {
1212

1313
export class AnotherComponent extends React.Component {
1414
static propTypes = {
15-
foo: React.PropTypes.string.isRequired,
15+
foo: PropTypes.string.isRequired,
1616
};
1717
render() {
1818
return <div />;

test/react-js-make-props-and-state-transform/multiple-components/output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type AnotherComponentProps = {
1313
};
1414
export class AnotherComponent extends React.Component<AnotherComponentProps, {}> {
1515
static propTypes = {
16-
foo: React.PropTypes.string.isRequired,
16+
foo: PropTypes.string.isRequired,
1717
};
1818
render() {
1919
return <div />;

test/react-js-make-props-and-state-transform/static-proptypes-getter-simple/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
export default class MyComponent extends React.Component {
44
static get propTypes() {
55
return {
6-
foo: React.PropTypes.string.isRequired,
6+
foo: PropTypes.string.isRequired,
77
};
88
}
99
render() {

test/react-js-make-props-and-state-transform/static-proptypes-getter-simple/output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type MyComponentProps = {
55
export default class MyComponent extends React.Component<MyComponentProps, {}> {
66
static get propTypes() {
77
return {
8-
foo: React.PropTypes.string.isRequired,
8+
foo: PropTypes.string.isRequired,
99
};
1010
}
1111
render() {

test/react-js-make-props-and-state-transform/static-proptypes-many-props/input.tsx

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,46 @@ import * as React from 'react';
22

33
export default class MyComponent extends React.Component {
44
static propTypes = {
5-
children: React.PropTypes.node,
6-
any: React.PropTypes.any,
7-
array: React.PropTypes.array,
8-
bool: React.PropTypes.bool,
9-
func: React.PropTypes.func,
10-
number: React.PropTypes.number,
11-
object: React.PropTypes.object,
12-
string: React.PropTypes.string,
13-
node: React.PropTypes.node,
14-
element: React.PropTypes.element,
15-
oneOf: React.PropTypes.oneOf(['a', 'b', 'c']),
16-
oneOfType: React.PropTypes.oneOfType([
17-
React.PropTypes.string,
18-
React.PropTypes.number,
5+
children: PropTypes.node,
6+
any: PropTypes.any,
7+
array: PropTypes.array,
8+
bool: PropTypes.bool,
9+
func: PropTypes.func,
10+
number: PropTypes.number,
11+
object: PropTypes.object,
12+
string: PropTypes.string,
13+
node: PropTypes.node,
14+
element: PropTypes.element,
15+
oneOf: PropTypes.oneOf(['a', 'b', 'c']),
16+
oneOfType: PropTypes.oneOfType([
17+
PropTypes.string,
18+
PropTypes.number,
1919
]),
20-
arrayOf: React.PropTypes.arrayOf(React.PropTypes.string),
21-
objectOf: React.PropTypes.objectOf(React.PropTypes.string),
22-
shape: React.PropTypes.shape({
23-
color: React.PropTypes.string,
24-
fontSize: React.PropTypes.number,
20+
arrayOf: PropTypes.arrayOf(PropTypes.string),
21+
objectOf: PropTypes.objectOf(PropTypes.string),
22+
shape: PropTypes.shape({
23+
color: PropTypes.string,
24+
fontSize: PropTypes.number,
2525
}),
26-
anyRequired: React.PropTypes.any.isRequired,
27-
arrayRequired: React.PropTypes.array.isRequired,
28-
boolRequired: React.PropTypes.bool.isRequired,
29-
funcRequired: React.PropTypes.func.isRequired,
30-
numberRequired: React.PropTypes.number.isRequired,
31-
objectRequired: React.PropTypes.object.isRequired,
32-
stringRequired: React.PropTypes.string.isRequired,
33-
nodeRequired: React.PropTypes.node.isRequired,
34-
elementRequired: React.PropTypes.element.isRequired,
35-
oneOfRequired: React.PropTypes.oneOf(['a', 'b', 'c']).isRequired,
36-
oneOfTypeRequired: React.PropTypes.oneOfType([
37-
React.PropTypes.string,
38-
React.PropTypes.number,
26+
anyRequired: PropTypes.any.isRequired,
27+
arrayRequired: PropTypes.array.isRequired,
28+
boolRequired: PropTypes.bool.isRequired,
29+
funcRequired: PropTypes.func.isRequired,
30+
numberRequired: PropTypes.number.isRequired,
31+
objectRequired: PropTypes.object.isRequired,
32+
stringRequired: PropTypes.string.isRequired,
33+
nodeRequired: PropTypes.node.isRequired,
34+
elementRequired: PropTypes.element.isRequired,
35+
oneOfRequired: PropTypes.oneOf(['a', 'b', 'c']).isRequired,
36+
oneOfTypeRequired: PropTypes.oneOfType([
37+
PropTypes.string,
38+
PropTypes.number,
3939
]).isRequired,
40-
arrayOfRequired: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
41-
objectOfRequired: React.PropTypes.objectOf(React.PropTypes.string).isRequired,
42-
shapeRequired: React.PropTypes.shape({
43-
color: React.PropTypes.string,
44-
fontSize: React.PropTypes.number.isRequired,
40+
arrayOfRequired: PropTypes.arrayOf(PropTypes.string).isRequired,
41+
objectOfRequired: PropTypes.objectOf(PropTypes.string).isRequired,
42+
shapeRequired: PropTypes.shape({
43+
color: PropTypes.string,
44+
fontSize: PropTypes.number.isRequired,
4545
}).isRequired,
4646
};
4747
render() {

test/react-js-make-props-and-state-transform/static-proptypes-many-props/output.tsx

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,40 @@ type MyComponentProps = {
4141
};
4242
export default class MyComponent extends React.Component<MyComponentProps, {}> {
4343
static propTypes = {
44-
children: React.PropTypes.node,
45-
any: React.PropTypes.any,
46-
array: React.PropTypes.array,
47-
bool: React.PropTypes.bool,
48-
func: React.PropTypes.func,
49-
number: React.PropTypes.number,
50-
object: React.PropTypes.object,
51-
string: React.PropTypes.string,
52-
node: React.PropTypes.node,
53-
element: React.PropTypes.element,
54-
oneOf: React.PropTypes.oneOf(['a', 'b', 'c']),
55-
oneOfType: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number]),
56-
arrayOf: React.PropTypes.arrayOf(React.PropTypes.string),
57-
objectOf: React.PropTypes.objectOf(React.PropTypes.string),
58-
shape: React.PropTypes.shape({
59-
color: React.PropTypes.string,
60-
fontSize: React.PropTypes.number,
44+
children: PropTypes.node,
45+
any: PropTypes.any,
46+
array: PropTypes.array,
47+
bool: PropTypes.bool,
48+
func: PropTypes.func,
49+
number: PropTypes.number,
50+
object: PropTypes.object,
51+
string: PropTypes.string,
52+
node: PropTypes.node,
53+
element: PropTypes.element,
54+
oneOf: PropTypes.oneOf(['a', 'b', 'c']),
55+
oneOfType: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
56+
arrayOf: PropTypes.arrayOf(PropTypes.string),
57+
objectOf: PropTypes.objectOf(PropTypes.string),
58+
shape: PropTypes.shape({
59+
color: PropTypes.string,
60+
fontSize: PropTypes.number,
6161
}),
62-
anyRequired: React.PropTypes.any.isRequired,
63-
arrayRequired: React.PropTypes.array.isRequired,
64-
boolRequired: React.PropTypes.bool.isRequired,
65-
funcRequired: React.PropTypes.func.isRequired,
66-
numberRequired: React.PropTypes.number.isRequired,
67-
objectRequired: React.PropTypes.object.isRequired,
68-
stringRequired: React.PropTypes.string.isRequired,
69-
nodeRequired: React.PropTypes.node.isRequired,
70-
elementRequired: React.PropTypes.element.isRequired,
71-
oneOfRequired: React.PropTypes.oneOf(['a', 'b', 'c']).isRequired,
72-
oneOfTypeRequired: React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number]).isRequired,
73-
arrayOfRequired: React.PropTypes.arrayOf(React.PropTypes.string).isRequired,
74-
objectOfRequired: React.PropTypes.objectOf(React.PropTypes.string).isRequired,
75-
shapeRequired: React.PropTypes.shape({
76-
color: React.PropTypes.string,
77-
fontSize: React.PropTypes.number.isRequired,
62+
anyRequired: PropTypes.any.isRequired,
63+
arrayRequired: PropTypes.array.isRequired,
64+
boolRequired: PropTypes.bool.isRequired,
65+
funcRequired: PropTypes.func.isRequired,
66+
numberRequired: PropTypes.number.isRequired,
67+
objectRequired: PropTypes.object.isRequired,
68+
stringRequired: PropTypes.string.isRequired,
69+
nodeRequired: PropTypes.node.isRequired,
70+
elementRequired: PropTypes.element.isRequired,
71+
oneOfRequired: PropTypes.oneOf(['a', 'b', 'c']).isRequired,
72+
oneOfTypeRequired: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
73+
arrayOfRequired: PropTypes.arrayOf(PropTypes.string).isRequired,
74+
objectOfRequired: PropTypes.objectOf(PropTypes.string).isRequired,
75+
shapeRequired: PropTypes.shape({
76+
color: PropTypes.string,
77+
fontSize: PropTypes.number.isRequired,
7878
}).isRequired,
7979
};
8080
render() {

test/react-js-make-props-and-state-transform/static-proptypes-simple/input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22

33
export default class MyComponent extends React.Component {
44
static propTypes = {
5-
foo: React.PropTypes.string.isRequired,
5+
foo: PropTypes.string.isRequired,
66
};
77
render() {
88
return <div />;

test/react-js-make-props-and-state-transform/static-proptypes-simple/output.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type MyComponentProps = {
44
};
55
export default class MyComponent extends React.Component<MyComponentProps, {}> {
66
static propTypes = {
7-
foo: React.PropTypes.string.isRequired,
7+
foo: PropTypes.string.isRequired,
88
};
99
render() {
1010
return <div />;

test/react-move-prop-types-to-class-transform/multiple-components/input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class SomeComponent extends React.Component<{
77
return null;
88
}
99
}
10-
SomeComponent.propTypes = { foo: React.PropTypes.string };
10+
SomeComponent.propTypes = { foo: PropTypes.string };
1111

1212
class AnotherComponent extends React.Component<{
1313
baz: number;
@@ -16,4 +16,4 @@ class AnotherComponent extends React.Component<{
1616
return null;
1717
}
1818
}
19-
AnotherComponent.propTypes = { baz: React.PropTypes.string };
19+
AnotherComponent.propTypes = { baz: PropTypes.string };

test/react-move-prop-types-to-class-transform/multiple-components/output.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ class SomeComponent extends React.Component<
66
bar: string;
77
}
88
> {
9-
static propTypes = { foo: React.PropTypes.string };
9+
static propTypes = { foo: PropTypes.string };
1010
render() {
1111
return null;
1212
}
1313
}
14-
SomeComponent.propTypes = { foo: React.PropTypes.string };
14+
SomeComponent.propTypes = { foo: PropTypes.string };
1515
class AnotherComponent extends React.Component<{
1616
baz: number;
1717
}> {
18-
static propTypes = { baz: React.PropTypes.string };
18+
static propTypes = { baz: PropTypes.string };
1919
render() {
2020
return null;
2121
}
2222
}
23-
AnotherComponent.propTypes = { baz: React.PropTypes.string };
23+
AnotherComponent.propTypes = { baz: PropTypes.string };

0 commit comments

Comments
 (0)