MCPcopy
hub / github.com/nestjs/swagger / getTypeReferenceAsString

Function getTypeReferenceAsString

lib/plugin/utils/plugin-utils.ts:36–129  ·  view source on GitHub ↗
(
  type: ts.Type,
  typeChecker: ts.TypeChecker,
  arrayDepth = 0
)

Source from the content-addressed store, hash-verified

34}
35
36export function getTypeReferenceAsString(
37 type: ts.Type,
38 typeChecker: ts.TypeChecker,
39 arrayDepth = 0
40): {
41 typeName: string;
42 isArray?: boolean;
43 arrayDepth?: number;
44} {
45 if (isArray(type)) {
46 const arrayType = getTypeArguments(type)[0];
47 const { typeName, arrayDepth: depth } = getTypeReferenceAsString(
48 arrayType,
49 typeChecker,
50 arrayDepth + 1
51 );
52 if (!typeName) {
53 return { typeName: undefined };
54 }
55 return {
56 typeName: `${typeName}`,
57 isArray: true,
58 arrayDepth: depth
59 };
60 }
61 if (isBoolean(type)) {
62 return { typeName: Boolean.name, arrayDepth };
63 }
64 if (isNumber(type)) {
65 return { typeName: Number.name, arrayDepth };
66 }
67 if (isBigInt(type)) {
68 return { typeName: BigInt.name, arrayDepth };
69 }
70 if (isString(type) || isStringLiteral(type) || isStringMapping(type)) {
71 return { typeName: String.name, arrayDepth };
72 }
73 if (isPromiseOrObservable(getText(type, typeChecker))) {
74 const typeArguments = getTypeArguments(type);
75 const elementType = getTypeReferenceAsString(
76 head(typeArguments),
77 typeChecker,
78 arrayDepth
79 );
80 return elementType;
81 }
82 if (type.isClass()) {
83 return { typeName: getText(type, typeChecker), arrayDepth };
84 }
85 try {
86 const text = getText(type, typeChecker);
87 if (text === Date.name) {
88 return { typeName: text, arrayDepth };
89 }
90 if (isOptionalBoolean(text)) {
91 return { typeName: Boolean.name, arrayDepth };
92 }
93 if (

Calls 15

isArrayFunction · 0.90
getTypeArgumentsFunction · 0.90
isBooleanFunction · 0.90
isNumberFunction · 0.90
isBigIntFunction · 0.90
isStringFunction · 0.90
isStringLiteralFunction · 0.90
isStringMappingFunction · 0.90
getTextFunction · 0.90
isInterfaceFunction · 0.90
isEnumFunction · 0.90
isPromiseOrObservableFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…