MCPcopy Create free account
hub / github.com/TanStack/query / declaredTypeLabel

Function declaredTypeLabel

scripts/generate-docs.ts:393–427  ·  view source on GitHub ↗
(
  outputDir: string,
  node: ts.TypeNode,
)

Source from the content-addressed store, hash-verified

391// The label of a declared type: the members of an intersection or union joined, a getter's result, the
392// keys of an object type, or the name looked up through the same wrappers as `typeNameInCode`.
393async function declaredTypeLabel(
394 outputDir: string,
395 node: ts.TypeNode,
396): Promise<string | undefined> {
397 if (ts.isParenthesizedTypeNode(node)) {
398 return declaredTypeLabel(outputDir, node.type)
399 }
400 if (ts.isIntersectionTypeNode(node) || ts.isUnionTypeNode(node)) {
401 const members = await Promise.all(
402 node.types.map((member) => declaredTypeLabel(outputDir, member)),
403 )
404 return members.every(Boolean)
405 ? members.join(ts.isIntersectionTypeNode(node) ? ' & ' : ' | ')
406 : undefined
407 }
408 if (ts.isFunctionTypeNode(node) && node.parameters.length === 0) {
409 const result = await declaredTypeLabel(outputDir, node.type)
410 return result && `() => ${result}`
411 }
412 if (ts.isTypeLiteralNode(node)) {
413 const keys = node.members
414 .map((member) => member.name?.getText())
415 .filter(Boolean)
416 return keys.length > 0 ? `{ ${keys.join(', ')} }` : undefined
417 }
418 if (
419 ts.isTypeReferenceNode(node) &&
420 typeTransforms.has(node.typeName.getText()) &&
421 node.typeArguments?.[0]
422 ) {
423 const target = await declaredTypeLabel(outputDir, node.typeArguments[0])
424 return target && `${node.typeName.getText()}<${target}>`
425 }
426 return typeNameInCode(outputDir, node.getText())
427}
428
429// The property table for the first type line that has one.
430async function findPropertiesTable(

Callers 1

addReferenceDetailsFunction · 0.85

Calls 1

typeNameInCodeFunction · 0.85

Tested by

no test coverage detected