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

Commit aa90f53

Browse files
committed
[New] add PropTypes.bigint
Closes #355
1 parent a921554 commit aa90f53

7 files changed

+87
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ MyComponent.propTypes = {
6767
// You can declare that a prop is a specific JS primitive. By default, these
6868
// are all optional.
6969
optionalArray: PropTypes.array,
70+
optionalBigInt: PropTypes.bigint,
7071
optionalBool: PropTypes.bool,
7172
optionalFunc: PropTypes.func,
7273
optionalNumber: PropTypes.number,

__tests__/PropTypesDevelopmentReact15.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ describe('PropTypesDevelopmentReact15', () => {
328328

329329
it('should not warn for valid values', () => {
330330
typeCheckPass(PropTypes.array, []);
331+
if (typeof BigInt === 'function') {
332+
typeCheckPass(PropTypes.bigint, BigInt(0));
333+
}
331334
typeCheckPass(PropTypes.bool, false);
332335
typeCheckPass(PropTypes.func, function() {});
333336
typeCheckPass(PropTypes.number, 0);
@@ -348,6 +351,7 @@ describe('PropTypesDevelopmentReact15', () => {
348351
typeCheckFailRequiredValues(PropTypes.array.isRequired);
349352
typeCheckFailRequiredValues(PropTypes.symbol.isRequired);
350353
typeCheckFailRequiredValues(PropTypes.number.isRequired);
354+
typeCheckFailRequiredValues(PropTypes.bigint.isRequired);
351355
typeCheckFailRequiredValues(PropTypes.bool.isRequired);
352356
typeCheckFailRequiredValues(PropTypes.func.isRequired);
353357
typeCheckFailRequiredValues(PropTypes.shape({}).isRequired);
@@ -361,6 +365,15 @@ describe('PropTypesDevelopmentReact15', () => {
361365
expectWarningInDevelopment(PropTypes.array.isRequired, []);
362366
expectWarningInDevelopment(PropTypes.array.isRequired, null);
363367
expectWarningInDevelopment(PropTypes.array.isRequired, undefined);
368+
expectWarningInDevelopment(PropTypes.bigint, function() {});
369+
expectWarningInDevelopment(PropTypes.bigint, 42);
370+
if (typeof BigInt === 'function') {
371+
expectWarningInDevelopment(PropTypes.bigint, BigInt(42));
372+
}
373+
expectWarningInDevelopment(PropTypes.bigint.isRequired, function() {});
374+
expectWarningInDevelopment(PropTypes.bigint.isRequired, 42);
375+
expectWarningInDevelopment(PropTypes.bigint.isRequired, null);
376+
expectWarningInDevelopment(PropTypes.bigint.isRequired, undefined);
364377
expectWarningInDevelopment(PropTypes.bool, []);
365378
expectWarningInDevelopment(PropTypes.bool, true);
366379
expectWarningInDevelopment(PropTypes.bool.isRequired, []);
@@ -436,6 +449,9 @@ describe('PropTypesDevelopmentReact15', () => {
436449

437450
it('should support the arrayOf propTypes', () => {
438451
typeCheckPass(PropTypes.arrayOf(PropTypes.number), [1, 2, 3]);
452+
if (typeof BigInt === 'function') {
453+
typeCheckPass(PropTypes.arrayOf(PropTypes.bigint), [BigInt(1), BigInt(2), BigInt(3)]);
454+
}
439455
typeCheckPass(PropTypes.arrayOf(PropTypes.string), ['a', 'b', 'c']);
440456
typeCheckPass(PropTypes.arrayOf(PropTypes.oneOf(['a', 'b'])), ['a', 'b']);
441457
typeCheckPass(PropTypes.arrayOf(PropTypes.symbol), [Symbol(), Symbol()]);
@@ -539,7 +555,6 @@ describe('PropTypesDevelopmentReact15', () => {
539555
});
540556

541557
describe('Component Type', () => {
542-
543558
it('should support components', () => {
544559
typeCheckPass(PropTypes.element, <div />);
545560
});
@@ -557,6 +572,14 @@ describe('PropTypesDevelopmentReact15', () => {
557572
'Invalid prop `testProp` of type `number` supplied to `testComponent`, ' +
558573
'expected a single ReactElement.',
559574
);
575+
if (typeof BigInt === 'function') {
576+
typeCheckFail(
577+
PropTypes.element,
578+
BigInt(123),
579+
'Invalid prop `testProp` of type `bigint` supplied to `testComponent`, ' +
580+
'expected a single ReactElement.',
581+
);
582+
}
560583
typeCheckFail(
561584
PropTypes.element,
562585
'foo',

__tests__/PropTypesDevelopmentStandalone-test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ describe('PropTypesDevelopmentStandalone', () => {
325325

326326
it('should not warn for valid values', () => {
327327
typeCheckPass(PropTypes.array, []);
328+
if (typeof BigInt === 'function') {
329+
typeCheckPass(PropTypes.bigint, BigInt(0));
330+
}
328331
typeCheckPass(PropTypes.bool, false);
329332
typeCheckPass(PropTypes.func, function() {});
330333
typeCheckPass(PropTypes.number, 0);
@@ -345,6 +348,7 @@ describe('PropTypesDevelopmentStandalone', () => {
345348
typeCheckFailRequiredValues(PropTypes.array.isRequired);
346349
typeCheckFailRequiredValues(PropTypes.symbol.isRequired);
347350
typeCheckFailRequiredValues(PropTypes.number.isRequired);
351+
typeCheckFailRequiredValues(PropTypes.bigint.isRequired);
348352
typeCheckFailRequiredValues(PropTypes.bool.isRequired);
349353
typeCheckFailRequiredValues(PropTypes.func.isRequired);
350354
typeCheckFailRequiredValues(PropTypes.shape({}).isRequired);
@@ -358,6 +362,15 @@ describe('PropTypesDevelopmentStandalone', () => {
358362
expectThrowsInDevelopment(PropTypes.array.isRequired, []);
359363
expectThrowsInDevelopment(PropTypes.array.isRequired, null);
360364
expectThrowsInDevelopment(PropTypes.array.isRequired, undefined);
365+
expectThrowsInDevelopment(PropTypes.bigint, function() {});
366+
expectThrowsInDevelopment(PropTypes.bigint, 42);
367+
if (typeof BigInt === 'function') {
368+
expectThrowsInDevelopment(PropTypes.bigint, BigInt(42));
369+
}
370+
expectThrowsInDevelopment(PropTypes.bigint.isRequired, function() {});
371+
expectThrowsInDevelopment(PropTypes.bigint.isRequired, 42);
372+
expectThrowsInDevelopment(PropTypes.bigint.isRequired, null);
373+
expectThrowsInDevelopment(PropTypes.bigint.isRequired, undefined);
361374
expectThrowsInDevelopment(PropTypes.bool, []);
362375
expectThrowsInDevelopment(PropTypes.bool, true);
363376
expectThrowsInDevelopment(PropTypes.bool.isRequired, []);
@@ -433,6 +446,9 @@ describe('PropTypesDevelopmentStandalone', () => {
433446

434447
it('should support the arrayOf propTypes', () => {
435448
typeCheckPass(PropTypes.arrayOf(PropTypes.number), [1, 2, 3]);
449+
if (typeof BigInt === 'function') {
450+
typeCheckPass(PropTypes.arrayOf(PropTypes.bigint), [BigInt(1), BigInt(2), BigInt(3)]);
451+
}
436452
typeCheckPass(PropTypes.arrayOf(PropTypes.string), ['a', 'b', 'c']);
437453
typeCheckPass(PropTypes.arrayOf(PropTypes.oneOf(['a', 'b'])), ['a', 'b']);
438454
typeCheckPass(PropTypes.arrayOf(PropTypes.symbol), [Symbol(), Symbol()]);
@@ -536,7 +552,6 @@ describe('PropTypesDevelopmentStandalone', () => {
536552
});
537553

538554
describe('Component Type', () => {
539-
540555
it('should support components', () => {
541556
typeCheckPass(PropTypes.element, <div />);
542557
});
@@ -554,6 +569,14 @@ describe('PropTypesDevelopmentStandalone', () => {
554569
'Invalid prop `testProp` of type `number` supplied to `testComponent`, ' +
555570
'expected a single ReactElement.',
556571
);
572+
if (typeof BigInt === 'function') {
573+
typeCheckFail(
574+
PropTypes.element,
575+
BigInt(123),
576+
'Invalid prop `testProp` of type `bigint` supplied to `testComponent`, ' +
577+
'expected a single ReactElement.',
578+
);
579+
}
557580
typeCheckFail(
558581
PropTypes.element,
559582
'foo',

__tests__/PropTypesProductionReact15-test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ describe('PropTypesProductionReact15', () => {
104104

105105
it('should not warn for valid values', () => {
106106
expectNoop(PropTypes.array, []);
107+
if (typeof BigInt === 'function') {
108+
expectNoop(PropTypes.bigint, BigInt(0));
109+
}
107110
expectNoop(PropTypes.bool, false);
108111
expectNoop(PropTypes.func, function() {});
109112
expectNoop(PropTypes.number, 0);
@@ -124,6 +127,7 @@ describe('PropTypesProductionReact15', () => {
124127
expectNoop(PropTypes.array.isRequired);
125128
expectNoop(PropTypes.symbol.isRequired);
126129
expectNoop(PropTypes.number.isRequired);
130+
expectNoop(PropTypes.bigint.isRequired);
127131
expectNoop(PropTypes.bool.isRequired);
128132
expectNoop(PropTypes.func.isRequired);
129133
expectNoop(PropTypes.shape({}).isRequired);
@@ -137,6 +141,15 @@ describe('PropTypesProductionReact15', () => {
137141
expectNoop(PropTypes.array.isRequired, []);
138142
expectNoop(PropTypes.array.isRequired, null);
139143
expectNoop(PropTypes.array.isRequired, undefined);
144+
expectNoop(PropTypes.bigint, function() {});
145+
expectNoop(PropTypes.bigint, 42);
146+
if (typeof BigInt === 'function') {
147+
expectNoop(PropTypes.bigint, BigInt(42));
148+
}
149+
expectNoop(PropTypes.bigint.isRequired, function() {});
150+
expectNoop(PropTypes.bigint.isRequired, 42);
151+
expectNoop(PropTypes.bigint.isRequired, null);
152+
expectNoop(PropTypes.bigint.isRequired, undefined);
140153
expectNoop(PropTypes.bool, []);
141154
expectNoop(PropTypes.bool, true);
142155
expectNoop(PropTypes.bool.isRequired, []);
@@ -212,6 +225,9 @@ describe('PropTypesProductionReact15', () => {
212225

213226
it('should support the arrayOf propTypes', () => {
214227
expectNoop(PropTypes.arrayOf(PropTypes.number), [1, 2, 3]);
228+
if (typeof BigInt === 'function') {
229+
expectNoop(PropTypes.arrayOf(PropTypes.bigint), [BigInt(1), BigInt(2), BigInt(3)]);
230+
}
215231
expectNoop(PropTypes.arrayOf(PropTypes.string), ['a', 'b', 'c']);
216232
expectNoop(PropTypes.arrayOf(PropTypes.oneOf(['a', 'b'])), ['a', 'b']);
217233
expectNoop(PropTypes.arrayOf(PropTypes.symbol), [Symbol(), Symbol()]);
@@ -315,7 +331,6 @@ describe('PropTypesProductionReact15', () => {
315331
});
316332

317333
describe('Component Type', () => {
318-
319334
it('should support components', () => {
320335
expectNoop(PropTypes.element, <div />);
321336
});
@@ -333,6 +348,14 @@ describe('PropTypesProductionReact15', () => {
333348
'Invalid prop `testProp` of type `number` supplied to `testComponent`, ' +
334349
'expected a single ReactElement.',
335350
);
351+
if (typeof BigInt === 'function') {
352+
expectNoop(
353+
PropTypes.element,
354+
BigInt(123),
355+
'Invalid prop `testProp` of type `bigint` supplied to `testComponent`, ' +
356+
'expected a single ReactElement.',
357+
);
358+
}
336359
expectNoop(
337360
PropTypes.element,
338361
'foo',

__tests__/PropTypesProductionStandalone-test.js

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ describe('PropTypesProductionStandalone', function() {
7676
expectThrowsInProduction(PropTypes.array.isRequired, /please/);
7777
expectThrowsInProduction(PropTypes.array.isRequired, null);
7878
expectThrowsInProduction(PropTypes.array.isRequired, undefined);
79+
expectThrowsInProduction(PropTypes.bigint, function() {});
80+
expectThrowsInProduction(PropTypes.bigint, 42);
81+
if (typeof BigInt === 'function') {
82+
expectThrowsInProduction(PropTypes.bigint, BigInt(42));
83+
}
84+
expectThrowsInProduction(PropTypes.bigint.isRequired, function() {});
85+
expectThrowsInProduction(PropTypes.bigint.isRequired, 42);
86+
expectThrowsInProduction(PropTypes.bigint.isRequired, null);
87+
expectThrowsInProduction(PropTypes.bigint.isRequired, undefined);
7988
expectThrowsInProduction(PropTypes.bool, []);
8089
expectThrowsInProduction(PropTypes.bool.isRequired, []);
8190
expectThrowsInProduction(PropTypes.bool.isRequired, null);
@@ -140,6 +149,9 @@ describe('PropTypesProductionStandalone', function() {
140149
it('should be a no-op', function() {
141150
expectThrowsInProduction(PropTypes.element, [<div />, <div />]);
142151
expectThrowsInProduction(PropTypes.element, 123);
152+
if (typeof BigInt === 'function') {
153+
expectThrowsInProduction(PropTypes.element, BigInt(123));
154+
}
143155
expectThrowsInProduction(PropTypes.element, 'foo');
144156
expectThrowsInProduction(PropTypes.element, false);
145157
expectThrowsInProduction(PropTypes.element.isRequired, null);

factoryWithThrowingShims.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = function() {
3535
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
3636
var ReactPropTypes = {
3737
array: shim,
38+
bigint: shim,
3839
bool: shim,
3940
func: shim,
4041
number: shim,

factoryWithTypeCheckers.js

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ module.exports = function(isValidElement, throwOnDirectAccess) {
114114
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
115115
var ReactPropTypes = {
116116
array: createPrimitiveTypeChecker('array'),
117+
bigint: createPrimitiveTypeChecker('bigint'),
117118
bool: createPrimitiveTypeChecker('boolean'),
118119
func: createPrimitiveTypeChecker('function'),
119120
number: createPrimitiveTypeChecker('number'),

0 commit comments

Comments
 (0)