Skip to content

Instantly share code, notes, and snippets.

@piksel
Created December 29, 2019 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piksel/8370652e4a29c2d99e2c74c18150a4b4 to your computer and use it in GitHub Desktop.
Save piksel/8370652e4a29c2d99e2c74c18150a4b4 to your computer and use it in GitHub Desktop.
import PropTypes from 'prop-types';
export function interfacePropType<T>(): PropTypes.Requireable<T> {
const validator = function(props: { [key: string]: any }, propName: string, componentName: string, location: string, propFullName: string)
{
return null;
}
validator.isRequired= function(props: {[key: string]: any}, propName: string, componentName: string){return null}
validator.get = function(target: any, prop: any) {
if(prop == PropTypes.nominalTypeHack) {
return { type: {} as T }
}
return target[prop];
}
return validator;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment