Open tebatalla opened 3 years ago
I definitely want to incorporate this, but it breaks functionality for Predicates. Can you create a zip of a project that fails against current version? I have a couple of my own I was using to test and having another would be useful for adjusting
Also, to give context: PropTypes.Requireable<T> = PropTypes.Validator<NonNullable<<T>>
which is what I'm already using
Strange, I can't reproduce now. tsc
was saying that Requirable
as defined by PropTypes
and RequireableValidator
as defined here weren't compatible. I'll explore a bit deeper if and when it comes up again.
Ok, couldn't reproduce before because I was using patch-package
and didn't see that I hadn't undone it. This is my tsc
output:
Type 'import("/xxx/node_modules/react-moment-proptypes/index").ReactMomentProptypes.Validator<moment.Moment>' is not assignable to type 'React.Validator<moment.Moment>'.
Types of property '[nominalTypeHack]' are incompatible.
Type '{ type: Moment | null | undefined; } | undefined' is not assignable to type '{ type: Moment; } | undefined'.
Type '{ type: Moment | null | undefined; }' is not assignable to type '{ type: Moment; }'.
Types of property 'type' are incompatible.
Type 'Moment | null | undefined' is not assignable to type 'Moment'.
Type 'undefined' is not assignable to type 'Moment'.
I'm not sure of the use case behind the predicate, but I'm calling the proptype check like this in my code:
import { momentObj } from 'react-moment-proptypes';
Component.propTypes = {
selectedDate: momentObj.isRequired,
}
I have no issue using the code in the fashion you describe without errors (it's even one of my examples in the README). Can you create a zip of the full project that I can pull and run? Or maybe include the tsconfig.json, lock file, and package.json?
I was still having issues with incorporating this. Inspired by airbnb's prop-type definitions I think that all you need to do is wrap the type with
Requireable
from PropTypes. I was able to compile with this change on a project with no problems.