prop-types icon indicating copy to clipboard operation
prop-types copied to clipboard

Access property type for documentation purposes at run time

Open zerekw opened this issue 8 years ago • 4 comments

Looking at how storybook and random questions on the internet it looks like it would be preferable to be able to pull the type of the property after it has been set.

I have a simple POC I can submit as a PR if that would be preferred. Code below as to what I would be expecting to have as an end result.

// this would be set with the validator
function getType() {
      return {
        type: type,
        subType: subType
      }
    }
propEnum.getType() => {type: "enum", subType: Array(4)}
propString.getType() => {type: "string", subType: undefined}

zerekw avatar May 18 '17 22:05 zerekw

Took me a while to track down the right package. Looks like it is regenerator. For me, it happens whenever I use a redux dispatch pattern in an async function. For example,

import { setLoading } from '../actions/loading'
import { connect } from 'react-redux'
...
class TestComponent {
  someMethod = async () => {
    // Shadowed variable, but no assignment
    const { setLoading } = this.props
    // expected (v0.13.4): setLoading = _this.props.setLoading;
    // actual (v0.14.0): _loading.setLoading = (_this.props.setLoading, function () {
    //    throw new Error('"' + "setLoading" + '" is read-only.');
    // }());
  }
}
...
connect(null, { setLoading })(TestComponent)

Workaround:

"resolutions": {
    "regenerator-transform": "0.13.4"
}

From my very limited understanding, this could be related to the hoisting changes in 0.14.0.

timmywil avatar Jun 08 '19 19:06 timmywil

I've a async function, when destructuring and save const show me error: Possible Unhandled Promise Rejection (id: 0): Error: “userOperations” is read-only , this worked for me (change let by const):

loadOrCreateCustomer = async () => { let { personalInformation, userOperations } = this.props; userOperations.setCardsByCustomer(cards); }

Dsantacruz avatar Sep 02 '19 17:09 Dsantacruz