(type: ts.TypeNode | undefined, references: AST.TypeReferences)
| 304 | } |
| 305 | |
| 306 | function parseType(type: ts.TypeNode | undefined, references: AST.TypeReferences): AST.Type { |
| 307 | if (!type) { |
| 308 | return { |
| 309 | name: 'void', |
| 310 | }; |
| 311 | } |
| 312 | |
| 313 | const leadingComments = getNodeComments(type); |
| 314 | |
| 315 | if (ts.isFunctionTypeNode(type)) { |
| 316 | return { |
| 317 | name: 'function', |
| 318 | leadingComments, |
| 319 | function: parseFunctionType(type, references), |
| 320 | }; |
| 321 | } |
| 322 | |
| 323 | if (ts.isUnionTypeNode(type)) { |
| 324 | const unions: AST.Type[] = []; |
| 325 | for (const unionType of type.types) { |
| 326 | unions.push(parseType(unionType, references)); |
| 327 | } |
| 328 | |
| 329 | return { |
| 330 | name: 'union', |
| 331 | leadingComments, |
| 332 | unions, |
| 333 | }; |
| 334 | } |
| 335 | |
| 336 | if (ts.isIntersectionTypeNode(type)) { |
| 337 | const intersections: AST.Type[] = []; |
| 338 | for (const unionType of type.types) { |
| 339 | intersections.push(parseType(unionType, references)); |
| 340 | } |
| 341 | |
| 342 | return { |
| 343 | name: 'intersection', |
| 344 | leadingComments, |
| 345 | intersections, |
| 346 | }; |
| 347 | } |
| 348 | |
| 349 | if (ts.isArrayTypeNode(type)) { |
| 350 | return { |
| 351 | name: 'array', |
| 352 | leadingComments, |
| 353 | array: parseType(type.elementType, references), |
| 354 | }; |
| 355 | } |
| 356 | |
| 357 | if (ts.isTypeReferenceNode(type) || ts.isExpressionWithTypeArguments(type)) { |
| 358 | const resolvedSymbol = resolveSymbol(type, references.typeChecker); |
| 359 | if (!resolvedSymbol) { |
| 360 | throw new Error(`Could not resolve symbol ${getNodeDebugDescription(type)}`); |
| 361 | } |
| 362 | |
| 363 | return parseTypeFromSymbolGroup(type, resolvedSymbol, leadingComments, references); |
no test coverage detected