MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / getTypeWithNullableInfo

Function getTypeWithNullableInfo

packages/alphatab/scripts/TypeSchema.ts:129–373  ·  view source on GitHub ↗
(
    program: ts.Program,
    node: ts.TypeNode | ts.Type,
    allowUnion: boolean,
    isOptionalFromDeclaration: boolean,
    typeArgumentMapping: Map<string, ts.Type> | undefined
)

Source from the content-addressed store, hash-verified

127}
128
129export function getTypeWithNullableInfo(
130 program: ts.Program,
131 node: ts.TypeNode | ts.Type,
132 allowUnion: boolean,
133 isOptionalFromDeclaration: boolean,
134 typeArgumentMapping: Map<string, ts.Type> | undefined
135): TypeWithNullableInfo {
136 const checker = program.getTypeChecker();
137
138 let typeInfo: Writeable<TypeWithNullableInfo> = {
139 isNullable: false,
140 isOptional: isOptionalFromDeclaration,
141 isUnionType: false,
142 isPrimitiveType: false,
143 isEnumType: false,
144 isTypedArray: false,
145 isOwnType: false,
146 typeAsString: '',
147 modulePath: '',
148 isJsonImmutable: false,
149 isNumberType: false,
150 isMap: false,
151 isSet: false,
152 isArray: false,
153 isCloneable: false,
154 createTypeNode() {
155 return undefined!;
156 }
157 };
158 let mainType: ts.Type | undefined;
159
160 const fillBaseInfoFrom = (tsType: ts.Type) => {
161 const valueDeclaration = tsType.symbol?.valueDeclaration;
162 mainType = tsType;
163
164 typeInfo.typeAsString = checker.typeToString(tsType, undefined, undefined);
165 typeInfo.modulePath = findModule(tsType, program.getCompilerOptions());
166 typeInfo.isOwnType =
167 !!typeInfo.modulePath && (!typeInfo.modulePath.includes('node_modules') || typeInfo.modulePath.includes('@coderline/alphatab')) && !!valueDeclaration;
168
169 if (isEnumType(tsType)) {
170 typeInfo.isEnumType = true;
171 } else if (isPrimitiveType(tsType)) {
172 typeInfo.isNumberType = isNumberType(tsType);
173 typeInfo.isPrimitiveType = true;
174 } else if (typeInfo.isOwnType) {
175 typeInfo.jsDocTags = valueDeclaration ? ts.getJSDocTags(valueDeclaration) : undefined;
176 if (typeInfo.jsDocTags) {
177 typeInfo.isJsonImmutable = !!typeInfo.jsDocTags.find(t => t.tagName.text === 'json_immutable');
178 typeInfo.isCloneable = !!typeInfo.jsDocTags.find(t => t.tagName.text === 'cloneable');
179 }
180
181 if (tsType.flags & ts.ObjectFlags.Reference) {
182 typeInfo.typeArguments = (tsType as ts.TypeReference).typeArguments?.map(p =>
183 getTypeWithNullableInfo(program, p, allowUnion, false, typeArgumentMapping)
184 );
185 }
186 } else if (checker.isArrayType(tsType)) {

Callers 4

createJsonMemberFunction · 0.90
handleMemberFunction · 0.85
fillBaseInfoFromFunction · 0.85

Calls 6

isPrimitiveTypeFunction · 0.90
isEnumTypeFunction · 0.90
fillBaseInfoFromFunction · 0.85
pushMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected