react-moment-proptypes
react-moment-proptypes copied to clipboard
Update index.d.ts
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.
Coverage remained the same at 100.0% when pulling 0e988d89f27b36a21949ffcc82e3aa3c00a9ebc9 on tebatalla:patch-2 into 89a61c17250ea7b71d55d2855f6739ae4071529a on CalebMorris:master.
Coverage remained the same at 100.0% when pulling 0e988d89f27b36a21949ffcc82e3aa3c00a9ebc9 on tebatalla:patch-2 into 89a61c17250ea7b71d55d2855f6739ae4071529a on CalebMorris:master.
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?