Skip to content

Commit 7a188d0

Browse files
psegalenerictraut
authored andcommitted
Switch PropTypes import from React to 'prop-types' package (#92)
* Switched PropTypes import from React to 'prop-types' package * Forgot to --save 'prop-types' npm package + Imported TypeDefinition from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/prop-types * Messed up bool.isRequired, my bad!
1 parent c1b2113 commit 7a188d0

5 files changed

Lines changed: 42 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"assert": "^1.3.0",
1313
"ifvisible.js": "^1.0.6",
1414
"lodash": "^4.17.1",
15+
"prop-types": "^15.5.9",
1516
"rebound": "^0.0.13",
1617
"synctasks": "^0.2.9"
1718
},

src/typings/prop-types.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
declare module 'prop-types' {
2+
// Type definitions for prop-types 15.5
3+
// Project: https://github.com/reactjs/prop-types
4+
// Definitions by: DovydasNavickas <https://github.com/DovydasNavickas>
5+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6+
// TypeScript Version: 2.2
7+
8+
export type Validator<T> = (object: T, key: string, componentName: string, ...rest: any[]) => Error | null;
9+
10+
// psegalen: modified original declaration because of
11+
// "error TS2312: An interface may only extend a class or another interface."
12+
export interface Requireable<T> {
13+
isRequired: Validator<T>;
14+
}
15+
16+
export type ValidationMap<T> = {[K in keyof T]?: Validator<T> };
17+
18+
export const any: Requireable<any> & Validator<any>;
19+
export const array: Requireable<any> & Validator<any>;
20+
export const bool: Requireable<any> & Validator<any>;
21+
export const func: Requireable<any> & Validator<any>;
22+
export const number: Requireable<any> & Validator<any>;
23+
export const object: Requireable<any> & Validator<any>;
24+
export const string: Requireable<any> & Validator<any>;
25+
export const node: Requireable<any> & Validator<any>;
26+
export const element: Requireable<any> & Validator<any>;
27+
export function instanceOf(expectedClass: {}): Requireable<any> & Validator<any>;
28+
export function oneOf(types: any[]): Requireable<any> & Validator<any>;
29+
export function oneOfType(types: Array<Validator<any>>): Requireable<any> & Validator<any>;
30+
export function arrayOf(type: Validator<any>): Requireable<any> & Validator<any>;
31+
export function objectOf(type: Validator<any>): Requireable<any> & Validator<any>;
32+
export function shape(type: ValidationMap<any>): Requireable<any> & Validator<any>;
33+
}

src/web/Image.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import _ = require('./utils/lodashMini');
1111
import React = require('react');
1212
import ReactDOM = require('react-dom');
1313
import SyncTasks = require('synctasks');
14+
import PropTypes = require('prop-types');
1415

1516
import restyleForInlineText = require('./utils/restyleForInlineText');
1617
import RX = require('../common/Interfaces');
@@ -114,12 +115,12 @@ class XhrBlobUrlCache {
114115

115116
export class Image extends RX.Image<ImageState> {
116117
static contextTypes: React.ValidationMap<any> = {
117-
isRxParentAText: React.PropTypes.bool
118+
isRxParentAText: PropTypes.bool
118119
};
119120
context: ImageContext;
120121

121122
static childContextTypes: React.ValidationMap<any> = {
122-
isRxParentAText: React.PropTypes.bool.isRequired
123+
isRxParentAText: PropTypes.bool.isRequired
123124
};
124125
getChildContext() {
125126
// Let descendant RX components know that their nearest RX ancestor is not an RX.Text.

src/web/Text.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import React = require('react');
1111
import ReactDOM = require('react-dom');
12+
import PropTypes = require('prop-types');
1213

1314
import AccessibilityUtil from './AccessibilityUtil';
1415
import RX = require('../common/Interfaces');
@@ -49,7 +50,7 @@ const _styles = {
4950

5051
export class Text extends RX.Text<void> {
5152
static childContextTypes: React.ValidationMap<any> = {
52-
isRxParentAText: React.PropTypes.bool.isRequired
53+
isRxParentAText: PropTypes.bool.isRequired
5354
};
5455

5556
getChildContext() {

src/web/View.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import React = require('react');
1111
import ReactDOM = require('react-dom');
12+
import PropTypes = require('prop-types');
1213

1314
import AccessibilityUtil from './AccessibilityUtil';
1415
import AnimateListEdits from './listAnimations/AnimateListEdits';
@@ -69,12 +70,12 @@ export interface ViewContext {
6970

7071
export class View extends ViewBase<Types.ViewProps, {}> {
7172
static contextTypes: React.ValidationMap<any> = {
72-
isRxParentAText: React.PropTypes.bool
73+
isRxParentAText: PropTypes.bool
7374
};
7475
context: ViewContext;
7576

7677
static childContextTypes: React.ValidationMap<any> = {
77-
isRxParentAText: React.PropTypes.bool.isRequired
78+
isRxParentAText: PropTypes.bool.isRequired
7879
};
7980

8081
private resizeDetectorAnimationFrame: number;

0 commit comments

Comments
 (0)