It’s just that the presence of a key in an object contextTypesseems wonderful (it is assumed that it uses it hasOwnPropertyunder the hood), but in order not to register any errors, the function returning nullseems necessary. This works both for contextTypesand for childContextTypes.
static contextTypes = {
router: () => null
};
static childContextTypes = {
location: () => null
};
getChildContext() {
return { location: this.props.location };
}
In some cases, TypeScript complains that it () => nulldoes not have a property isRequired. I solved this by creating a helper function fakePropType:
const fakePropType: any = () => null
fakeProptype.isRequired = () => null
source
share