Skip to content

⬅️ Back to Table of Contents

πŸ“„ TypeInfo

πŸ“Š Analysis Summary

Metric Count
πŸ”§ Functions 3
πŸ“¦ Imports 5
πŸ’  JSX Elements 20
πŸ“ Interfaces 4

πŸ“š Table of Contents

πŸ› οΈ File Location:

πŸ“‚ packages/website/src/components/typeDetails/TypeInfo.tsx

πŸ“¦ Imports

Name Source
useMemo react
React react
OnHoverNodeFn ../ast/types
ASTViewer ../ast/ASTViewer
astStyles ../ast/ASTViewer.module.css

JSX Elements

Component Type Props Children
div element className={astStyles.list} , ,
span element className={astStyles.propClass} {props.label}
span element none text: ":"
span element className={astStyles.propString} {String(props.value)}
Fragment fragment none

h4 element className="padding--sm margin--none" {props.label}
Fragment fragment none
SimpleField component label="typeToString()", value={props.string} none
ASTViewer component onHoverNode={props.onHoverNode}, value={props.type} none
div element className={astStyles.list} text: "None"
div element none text: "TypeChecker not available"
div element none none
Fragment fragment none

, , , , , , <TypeG...

h4 element className="padding--sm margin--none" text: "Node"
ASTViewer component onHoverNode={onHoverNode}, value={value} none
TypeGroup component label="Type", onHoverNode={onHoverNode}, string={computed.typeString}, type={... none
TypeGroup component label="Contextual Type", onHoverNode={onHoverNode}, string={computed.contextu... none
TypeGroup component label="Symbol", onHoverNode={onHoverNode}, type={computed.symbol} none
TypeGroup component label="Signature", onHoverNode={onHoverNode}, type={computed.signature} none
TypeGroup component label="FlowNode", onHoverNode={onHoverNode}, type={computed.flowNode} none

Functions

TypeInfo({ onHoverNode, typeChecker, val…: TypeInfoProps): React.JSX.Element

Parameters:

  • { onHoverNode, typeChecker, value, } TypeInfoProps

Returns: React.JSX.Element

Calls:

  • useMemo (from react)
  • typeChecker.getTypeAtLocation
  • typeChecker.typeToString
  • type.getSymbol
  • type.getCallSignatures
  • type.getConstructSignatures
  • typeChecker.getContextualType

Internal Comments:

// @ts-expect-error not part of public api (x4)
// @ts-expect-error just fail if a node type is not correct (x2)

Code
export function TypeInfo({
  onHoverNode,
  typeChecker,
  value,
}: TypeInfoProps): React.JSX.Element {
  const computed = useMemo(() => {
    if (!typeChecker) {
      return undefined;
    }
    const info: InfoModel = {};
    try {
      const type = typeChecker.getTypeAtLocation(value);
      info.type = type;
      info.typeString = typeChecker.typeToString(type);
      info.symbol = type.getSymbol();
      let signature = type.getCallSignatures();
      if (signature.length === 0) {
        signature = type.getConstructSignatures();
      }
      info.signature = signature.length > 0 ? signature : undefined;
      // @ts-expect-error not part of public api
      info.flowNode = value.flowNode ?? value.endFlowNode ?? undefined;
    } catch (e: unknown) {
      info.type = e;
    }
    try {
      // @ts-expect-error just fail if a node type is not correct
      const contextualType = typeChecker.getContextualType(value);
      info.contextualType = contextualType;
      if (contextualType) {
        info.contextualTypeString = typeChecker.typeToString(contextualType);
      }
    } catch {
      info.contextualType = undefined;
    }
    return info;
  }, [value, typeChecker]);

  if (!typeChecker || !computed) {
    return <div>TypeChecker not available</div>;
  }

  return (
    <div>
      <>
        <h4 className="padding--sm margin--none">Node</h4>
        <ASTViewer onHoverNode={onHoverNode} value={value} />
        <TypeGroup
          label="Type"
          onHoverNode={onHoverNode}
          string={computed.typeString}
          type={computed.type}
        />
        <TypeGroup
          label="Contextual Type"
          onHoverNode={onHoverNode}
          string={computed.contextualTypeString}
          type={computed.contextualType}
        />
        <TypeGroup
          label="Symbol"
          onHoverNode={onHoverNode}
          type={computed.symbol}
        />
        <TypeGroup
          label="Signature"
          onHoverNode={onHoverNode}
          type={computed.signature}
        />
        <TypeGroup
          label="FlowNode"
          onHoverNode={onHoverNode}
          type={computed.flowNode}
        />
      </>
    </div>
  );
}

SimpleField(props: SimpleFieldProps): React.JSX.Element

Parameters:

  • props SimpleFieldProps

Returns: React.JSX.Element

Calls:

  • String
Code
function SimpleField(props: SimpleFieldProps): React.JSX.Element {
  return (
    <div className={astStyles.list}>
      <span className={astStyles.propClass}>{props.label}</span>
      <span>: </span>
      <span className={astStyles.propString}>{String(props.value)}</span>
    </div>
  );
}

TypeGroup(props: TypeGroupProps): React.JSX.Element

Parameters:

  • props TypeGroupProps

Returns: React.JSX.Element

Code
function TypeGroup(props: TypeGroupProps): React.JSX.Element {
  return (
    <>
      <h4 className="padding--sm margin--none">{props.label}</h4>
      {props.type ? (
        <>
          {props.string && (
            <SimpleField label="typeToString()" value={props.string} />
          )}
          <ASTViewer onHoverNode={props.onHoverNode} value={props.type} />
        </>
      ) : (
        <div className={astStyles.list}>None</div>
      )}
    </>
  );
}

Interfaces

TypeInfoProps

Interface Code
export interface TypeInfoProps {
  readonly onHoverNode?: OnHoverNodeFn;
  readonly typeChecker?: ts.TypeChecker;
  readonly value: ts.Node;
}

Properties

Name Type Optional Description
onHoverNode OnHoverNodeFn βœ“ not shown
typeChecker ts.TypeChecker βœ“ not shown
value ts.Node βœ— not shown

InfoModel

Interface Code
interface InfoModel {
  contextualType?: unknown;
  contextualTypeString?: string;
  flowNode?: unknown;
  signature?: unknown;
  symbol?: unknown;
  type?: unknown;
  typeString?: string;
}

Properties

Name Type Optional Description
contextualType unknown βœ“ not shown
contextualTypeString string βœ“ not shown
flowNode unknown βœ“ not shown
signature unknown βœ“ not shown
symbol unknown βœ“ not shown
type unknown βœ“ not shown
typeString string βœ“ not shown

SimpleFieldProps

Interface Code
interface SimpleFieldProps {
  readonly label: string;
  readonly value: string | undefined;
}

Properties

Name Type Optional Description
label string βœ— not shown
value string \| undefined βœ— not shown

TypeGroupProps

Interface Code
interface TypeGroupProps {
  readonly label: string;
  readonly onHoverNode?: OnHoverNodeFn;
  readonly string?: string;
  readonly type?: unknown;
}

Properties

Name Type Optional Description
label string βœ— not shown
onHoverNode OnHoverNodeFn βœ“ not shown
string string βœ“ not shown
type unknown βœ“ not shown

Generated by Syntax Scribe