How to use the kind2string.resolveFromGeneric function in kind2string

To help you get started, we’ve selected a few kind2string examples, based on popular ways it is used in public projects.

github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / index.js View on Github external
render() {
    let { shouldCollapse, typeValue: type, components } = this.props;
    // any instance of returning null means we are confident the information will
    // be displayed elsewhere so we do not need to also include it here.
    if (type.kind === 'generic') {
      type = resolveFromGeneric(type);
    }
    if (SIMPLE_TYPES.includes(type.kind)) return null;
    if (type.kind === 'nullable' && SIMPLE_TYPES.includes(type.arguments.kind)) {
      return null;
    }

    return shouldCollapse ? (
      <Toggle
        beginClosed
        afterCollapse={(isCollapsed, toggleCollapse) => (
          <div>
            <components.Button isCollapsed={isCollapsed} onClick={toggleCollapse}>
              {isCollapsed ? 'Expand Prop Shape' : 'Hide Prop Shape'}
            </components.Button>
          </div>
        )}
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / converters.js View on Github external
{type.members.map(prop => {
              if (prop.kind === "spread") {
                const nestedObj = resolveFromGeneric(prop.value);
                // Spreads almost always resolve to an object, but they can
                // also resolve to an import. We just allow it to fall through
                // to prettyConvert if there are no members
                if (nestedObj.members) {
                  return nestedObj.members.map(newProp =>
                    prettyConvert(newProp, components, depth)
                  );
                }
              }
              return prettyConvert(prop, components, depth);
            })}
          </components.Indent>
github Noviny / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
{type.members.map(prop => {
              if (prop.kind === 'spread') {
                const nestedObj = resolveFromGeneric(prop.value);
                // Spreads almost always resolve to an object, but they can
                // also resolve to an import. We just allow it to fall through
                // to prettyConvert if there are no members
                if (nestedObj.members) {
                  return nestedObj.members.map(newProp =>
                    prettyConvert(newProp, components, depth),
                  );
                }
              }
              return prettyConvert(prop, components, depth);
            })}
          </components.Indent>
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
{type.members.filter(p => p).map(prop => {
              if (prop.kind === 'spread') {
                const nestedObj = resolveFromGeneric(prop.value);
                // Spreads almost always resolve to an object, but they can
                // also resolve to an import. We just allow it to fall through
                // to prettyConvert if there are no members
                if (nestedObj.members) {
                  return nestedObj.members.map(newProp =>
                    prettyConvert(newProp, components, depth)
                  );
                }
              }
              return prettyConvert(prop, components, depth);
            })}
          </components.Indent>
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / index.js View on Github external
render() {
    let { shouldCollapse, typeValue: type, components } = this.props;
    // any instance of returning null means we are confident the information will
    // be displayed elsewhere so we do not need to also include it here.
    if (type.kind === "generic") {
      type = resolveFromGeneric(type);
    }
    if (SIMPLE_TYPES.includes(type.kind)) return null;
    if (
      type.kind === "nullable" &&
      SIMPLE_TYPES.includes(type.arguments.kind)
    ) {
      return null;
    }

    return shouldCollapse ? (
      <Toggle
        beginClosed
        afterCollapse={(isCollapsed, toggleCollapse) => (
          <div>
            <components.Button
              isCollapsed={isCollapsed}
github Noviny / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
return (
        <span>
          <components.TypeMeta>{convert(type.value)}</components.TypeMeta>
          <AddBrackets openBracket="<" closeBracket=">">
            {type.typeParams &&
              type.typeParams.params.map((param, index, array) => (
                <span key={index}>
                  {prettyConvert(param, components, depth)}
                  {type.typeParams && index === array.length - 1 ? '' : ', '}
                </span>
              ))}
          </AddBrackets>
        </span>
      );
    }
    return prettyConvert(resolveFromGeneric(type), components);
  },
  object: (type: K.Obj, components: Components, depth: number) => {
github mitchellhamilton / magical-types / packages / pretty / src / pretty-proptypes / PrettyConvert / converters.js View on Github external
return (
        <span>
          <components.TypeMeta>{convert(type.value)}</components.TypeMeta>
          <AddBrackets openBracket="<" closeBracket=">">
            {type.typeParams &&
              type.typeParams.params.map((param, index, array) => (
                <span key={index}>
                  {prettyConvert(param, components, depth)}
                  {type.typeParams && index === array.length - 1 ? "" : ", "}
                </span>
              ))}
          </AddBrackets>
        </span>
      );
    }
    return prettyConvert(resolveFromGeneric(type), components);
  },
  object: (type: K.Obj, components: Components, depth: number) => {
github Noviny / pretty-proptypes / src / getPropTypes.js View on Github external
const getPropTypes = (propTypesObj: Kind) => {
  let resolvedTypes = resolveFromGeneric(propTypesObj);
  let propTypes;
  if (resolvedTypes.kind === 'object') {
    propTypes = resolvedTypes.members;
  } else if (resolvedTypes.kind === 'intersection') {
    propTypes = resolvedTypes.types.reduce(
      (acc, type) => [...acc, ...reduceToObj(type)],
      [],
    );
  }
  return propTypes;
};
github atlassian / extract-react-types / packages / pretty-proptypes / src / PrettyConvert / converters.js View on Github external
return (
        <span>
          <components.TypeMeta>{convert(type.value)}</components.TypeMeta>
          <AddBrackets openBracket="<" closeBracket=">">
            {type.typeParams &&
              type.typeParams.params.map((param, index, array) => (
                <span key={index}>
                  {prettyConvert(param, components, depth)}
                  {type.typeParams && index === array.length - 1 ? '' : ', '}
                </span>
              ))}
          </AddBrackets>
        </span>
      );
    }
    return prettyConvert(resolveFromGeneric(type), components);
  },
  object: (type: K.Obj, components: Components, depth: number) => {
github atlassian / extract-react-types / packages / pretty-proptypes / src / getPropTypes.js View on Github external
const getPropTypes = (propTypesObj: Kind) => {
  let resolvedTypes = resolveFromGeneric(propTypesObj);
  let propTypes;
  if (resolvedTypes.kind === 'object') {
    propTypes = resolvedTypes.members;
  } else if (resolvedTypes.kind === 'intersection') {
    propTypes = resolvedTypes.types.reduce((acc, type) => [...acc, ...reduceToObj(type)], []);
  }
  return propTypes;
};

kind2string

Utility to ensure extract-react-types output can be rendered without errors

MIT
Latest version published 2 years ago

Package Health Score

63 / 100
Full package analysis

Similar packages