β¬ οΈ 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 | , |
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.getTypeAtLocationtypeChecker.typeToStringtype.getSymboltype.getCallSignaturestype.getConstructSignaturestypeChecker.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:
propsSimpleFieldProps
Returns: React.JSX.Element
Calls:
String
Code
TypeGroup(props: TypeGroupProps): React.JSX.Element¶
Parameters:
propsTypeGroupProps
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
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
onHoverNode |
OnHoverNodeFn |
β | not shown |
typeChecker |
ts.TypeChecker |
β | not shown |
value |
ts.Node |
β | not shown |
InfoModel¶
Interface Code
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
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
label |
string |
β | not shown |
value |
string \| undefined |
β | not shown |
TypeGroupProps¶
Interface Code
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