react-moment-proptypes icon indicating copy to clipboard operation
react-moment-proptypes copied to clipboard

Update index.d.ts

Open tebatalla opened this issue 3 years ago • 7 comments

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.

tebatalla avatar Mar 25 '21 17:03 tebatalla

Coverage Status

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

coveralls avatar Mar 25 '21 17:03 coveralls

Coverage Status

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

coveralls avatar Mar 25 '21 17:03 coveralls

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 avatar Mar 26 '21 02:03 CalebMorris

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

CalebMorris avatar Mar 26 '21 04:03 CalebMorris

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 avatar Mar 26 '21 16:03 tebatalla

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,
}

tebatalla avatar Mar 26 '21 17:03 tebatalla

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?

CalebMorris avatar Mar 27 '21 01:03 CalebMorris