Skip to content

PropTypes.oneOf with named imports has weird result #379

Closed
@superMDguy

Description

@superMDguy

Example Component

import React from 'react'
import PropTypes from 'prop-types'
import { DEFAULT_NAME_1, DEFAULT_NAME_2 } from './constants'

export default class ExampleComponent extends React.Component {
  render() {
    return <div>Hello {name}</div>
  }
}

ExampleComponent.propTypes = {
  name: PropTypes.oneOf([DEFAULT_NAME_1, DEFAULT_NAME_2])
}

Output Docgen

{
  "description": "",
  "displayName": "ExampleComponent",
  "methods": [],
  "props": {
    "name": {
      "type": {
        "name": "enum",
        "value": [
          {
            "value": "import { DEFAULT_NAME_1, DEFAULT_NAME_2 } from './constants'",
            "computed": true
          },
          {
            "value": "import { DEFAULT_NAME_1, DEFAULT_NAME_2 } from './constants'",
            "computed": true
          }
        ]
      },
      "required": false,
      "description": ""
    }
  }
}

There's no perfect way to handle this (without trying to follow imports), but I'd prefer just using the name of the imported constant as the prop value, like what happens with import * as consts from './consts'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions