Skip to content
Closed
Changes from all 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
21 changes: 21 additions & 0 deletions src/isomorphic/classic/types/ReactPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var ReactPropTypes = {
oneOf: createEnumTypeChecker,
oneOfType: createUnionTypeChecker,
shape: createShapeTypeChecker,
symbol: createSymbolTypeChecker(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be symbol: createSymbolTypeChecker, (without () at the end)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling the createSymbolTypeChecker returns the chainable type checker, right?
As you would do something like: React.PropTypes.symbol.isRequired and not React.PropTypes.symbol().isRequired (am I wrong?)

};

/**
Expand Down Expand Up @@ -359,6 +360,26 @@ function createShapeTypeChecker(shapeTypes) {
return createChainableTypeChecker(validate);
}

function createSymbolTypeChecker() {
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
var propType = getPropType(propValue);

// If it behaves like a Symbol, it is a Symbol.
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
if ((propType !== 'symbol') && (propValue['@@toStringTag'] !== 'Symbol')) {
return new Error(
`Invalid ${location} \`${propFullName}\` of type \`${propType}\` ` +
`supplied to \`${componentName}\`, expected \`symbol\`.`
);
}

return null;
}
return createChainableTypeChecker(validate);
}


function isNode(propValue) {
switch (typeof propValue) {
case 'number':
Expand Down