CalebMorris / react-moment-proptypes

React proptype validator for moment.js
49 stars 17 forks source link

Update index.d.ts #51

Open tebatalla opened 3 years ago

tebatalla commented 3 years ago

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.

coveralls commented 3 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 0e988d89f27b36a21949ffcc82e3aa3c00a9ebc9 on tebatalla:patch-2 into 89a61c17250ea7b71d55d2855f6739ae4071529a on CalebMorris:master.

coveralls commented 3 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 0e988d89f27b36a21949ffcc82e3aa3c00a9ebc9 on tebatalla:patch-2 into 89a61c17250ea7b71d55d2855f6739ae4071529a on CalebMorris:master.

CalebMorris commented 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

CalebMorris commented 3 years ago

Also, to give context: PropTypes.Requireable<T> = PropTypes.Validator<NonNullable<<T>> which is what I'm already using

tebatalla commented 3 years ago

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.

tebatalla commented 3 years ago

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,
 }
CalebMorris commented 3 years ago

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?