MCPcopy Create free account
hub / github.com/arktypeio/arktype / unreadAnnotationOf

Method unreadAnnotationOf

ark/aot/graph.ts:2054–2077  ·  view source on GitHub ↗
(node: Node, module: SourceModule)

Source from the content-addressed store, hash-verified

2052
2053 // e.g. `Params` for `p` in `(p: Params) => p.or`, where `Params` is computed or `any`
2054 unreadAnnotationOf(node: Node, module: SourceModule): Node | undefined {
2055 let annotated = castOf(node)
2056 if (!annotated) {
2057 const id = unwrapChain(node)
2058 const binding = module.scopes.byId.get(id)?.binding
2059 const declaration = binding?.declaration
2060 // e.g. `def as Piped` for `p` in `const p = def as Piped`
2061 annotated =
2062 (
2063 declaration?.type === "VariableDeclarator" &&
2064 declaration.id === binding!.id &&
2065 declaration.init
2066 ) ?
2067 (castOf(declaration.init) ?? binding!.id)
2068 : binding?.id
2069 }
2070 const annotation =
2071 annotated && "typeAnnotation" in annotated ?
2072 annotated.typeAnnotation
2073 : undefined
2074 if (!annotation) return
2075 const kind = this.annotatedKindOf(annotated!, module, this.finalKindOfKey)
2076 return kind === undefined || kind & kinds.opaque ? annotation : undefined
2077 }
2078
2079 // e.g. unsure for `t: Type`, data for `s: JsonSchema`, none for `any`
2080 private annotatedKindOf(

Callers 1

Calls 4

annotatedKindOfMethod · 0.95
unwrapChainFunction · 0.90
castOfFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected