• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brighterscript / #15035

15 Dec 2025 08:42PM UTC coverage: 86.889%. Remained the same
#15035

push

web-flow
Merge a60226157 into 2ea4d2108

14466 of 17575 branches covered (82.31%)

Branch coverage included in aggregate %.

113 of 217 new or added lines in 8 files covered. (52.07%)

116 existing lines in 6 files now uncovered.

15185 of 16550 relevant lines covered (91.75%)

24075.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.61
/src/astUtils/reflection.ts
1
import type { Body, AssignmentStatement, Block, ExpressionStatement, FunctionStatement, IfStatement, IncrementStatement, PrintStatement, GotoStatement, LabelStatement, ReturnStatement, EndStatement, StopStatement, ForStatement, ForEachStatement, WhileStatement, DottedSetStatement, IndexedSetStatement, LibraryStatement, NamespaceStatement, ImportStatement, ClassStatement, InterfaceFieldStatement, InterfaceMethodStatement, InterfaceStatement, EnumStatement, EnumMemberStatement, TryCatchStatement, CatchStatement, ThrowStatement, MethodStatement, FieldStatement, ConstStatement, ContinueStatement, DimStatement, TypecastStatement, AliasStatement, AugmentedAssignmentStatement, ConditionalCompileConstStatement, ConditionalCompileErrorStatement, ConditionalCompileStatement, ExitStatement, TypeStatement } from '../parser/Statement';
2
import type { LiteralExpression, BinaryExpression, CallExpression, FunctionExpression, DottedGetExpression, XmlAttributeGetExpression, IndexedGetExpression, GroupingExpression, EscapedCharCodeLiteralExpression, ArrayLiteralExpression, AALiteralExpression, UnaryExpression, VariableExpression, SourceLiteralExpression, NewExpression, CallfuncExpression, TemplateStringQuasiExpression, TemplateStringExpression, TaggedTemplateStringExpression, AnnotationExpression, FunctionParameterExpression, AAMemberExpression, TernaryExpression, NullCoalescingExpression, PrintSeparatorExpression, TypecastExpression, TypedArrayExpression, TypeExpression, InlineInterfaceMemberExpression, InlineInterfaceExpression } from '../parser/Expression';
3
import type { BrsFile } from '../files/BrsFile';
4
import type { XmlFile } from '../files/XmlFile';
5
import type { BsDiagnostic, TypedefProvider } from '../interfaces';
6
import type { InvalidType } from '../types/InvalidType';
7
import type { VoidType } from '../types/VoidType';
8
import { InternalWalkMode } from './visitors';
1✔
9
import type { TypedFunctionType } from '../types/TypedFunctionType';
10
import type { FunctionType } from '../types/FunctionType';
11
import type { StringType } from '../types/StringType';
12
import type { BooleanType } from '../types/BooleanType';
13
import type { IntegerType } from '../types/IntegerType';
14
import type { LongIntegerType } from '../types/LongIntegerType';
15
import type { FloatType } from '../types/FloatType';
16
import type { DoubleType } from '../types/DoubleType';
17
import type { ClassType } from '../types/ClassType';
18
import type { Scope } from '../Scope';
19
import type { XmlScope } from '../XmlScope';
20
import type { DynamicType } from '../types/DynamicType';
21
import type { InterfaceType } from '../types/InterfaceType';
22
import type { ObjectType } from '../types/ObjectType';
23
import type { AstNode, Expression, Statement } from '../parser/AstNode';
24
import type { AssetFile } from '../files/AssetFile';
25
import { AstNodeKind } from '../parser/AstNode';
1✔
26
import type { TypePropertyReferenceType, ReferenceType, BinaryOperatorReferenceType, ArrayDefaultTypeReferenceType, AnyReferenceType, ParamTypeFromValueReferenceType } from '../types/ReferenceType';
27
import type { EnumMemberType, EnumType } from '../types/EnumType';
28
import type { UnionType } from '../types/UnionType';
29
import type { UninitializedType } from '../types/UninitializedType';
30
import type { ArrayType } from '../types/ArrayType';
31
import type { InheritableType } from '../types/InheritableType';
32
import type { CallFuncableType } from '../types/CallFuncableType';
33
import { BscTypeKind } from '../types/BscTypeKind';
1✔
34
import type { NamespaceType } from '../types/NamespaceType';
35
import type { BaseFunctionType } from '../types/BaseFunctionType';
36
import type { BscFile } from '../files/BscFile';
37
import type { ComponentType } from '../types/ComponentType';
38
import type { AssociativeArrayType } from '../types/AssociativeArrayType';
39
import { TokenKind } from '../lexer/TokenKind';
1✔
40
import type { Program } from '../Program';
41
import type { Project } from '../lsp/Project';
42
import type { IntersectionType } from '../types/IntersectionType';
43
import type { TypeStatementType } from '../types/TypeStatementType';
44

45

46
// File reflection
47
export function isBrsFile(file: BscFile | undefined): file is BrsFile {
1✔
48
    return file?.constructor.name === 'BrsFile';
105,696✔
49
}
50

51
export function isXmlFile(file: (BscFile | XmlFile | undefined)): file is XmlFile {
1✔
52
    return file?.constructor.name === 'XmlFile';
22,960✔
53
}
54

55
export function isAssetFile(file: (BscFile | AssetFile | undefined)): file is AssetFile {
1✔
56
    return file?.constructor.name === 'AssetFile';
12!
57
}
58

59
export function isBscFile(file: (BscFile | BscFile | XmlFile | AssetFile | undefined)): file is BscFile {
1✔
UNCOV
60
    return isBrsFile(file) || isXmlFile(file) || isAssetFile(file);
×
61
}
62

63

64
export function isXmlScope(scope: (Scope | undefined)): scope is XmlScope {
1✔
65
    return scope?.constructor.name === 'XmlScope';
4,707!
66
}
67

68

69
export function isProgram(arg: any): arg is Program {
1✔
UNCOV
70
    return arg?.constructor.name === 'Program';
×
71
}
72

73
export function isProject(arg: any): arg is Project {
1✔
UNCOV
74
    return arg?.constructor.name === 'Project';
×
75
}
76

77

78
// Statements reflection
79

80
/**
81
 * Determine if the variablvalue is a descendent of the Statement base class.
82
 * Due to performance restrictions, this expects all statements to
83
 * directly extend Statement or FunctionStatement,
84
 * so it only checks the immediate parent's class name.
85
 */
86
export function isStatement(element: AstNode | undefined): element is Statement {
1✔
87
    // eslint-disable-next-line no-bitwise
88
    return !!(element && element.visitMode & InternalWalkMode.visitStatements);
36,426✔
89
}
90

91
export function isBody(element: AstNode | undefined): element is Body {
1✔
92
    return element?.constructor?.name === 'Body';
111,877!
93
}
94
export function isAssignmentStatement(element: AstNode | undefined): element is AssignmentStatement {
1✔
95
    return element?.kind === AstNodeKind.AssignmentStatement;
19,387✔
96
}
97
export function isBlock(element: AstNode | undefined): element is Block {
1✔
98
    return element?.constructor?.name === 'Block';
119,655✔
99
}
100
export function isExpressionStatement(element: AstNode | undefined): element is ExpressionStatement {
1✔
101
    return element?.kind === AstNodeKind.ExpressionStatement;
336!
102
}
103
export function isExitStatement(element: AstNode | undefined): element is ExitStatement {
1✔
104
    return element?.kind === AstNodeKind.ExitStatement;
6!
105
}
106
export function isFunctionStatement(element: AstNode | undefined): element is FunctionStatement {
1✔
107
    return element?.kind === AstNodeKind.FunctionStatement;
31,845✔
108
}
109
export function isIfStatement(element: AstNode | undefined): element is IfStatement {
1✔
110
    return element?.kind === AstNodeKind.IfStatement;
4,674✔
111
}
112
export function isIncrementStatement(element: AstNode | undefined): element is IncrementStatement {
1✔
113
    return element?.kind === AstNodeKind.IncrementStatement;
8!
114
}
115
export function isPrintStatement(element: AstNode | undefined): element is PrintStatement {
1✔
116
    return element?.kind === AstNodeKind.PrintStatement;
394!
117
}
118
export function isGotoStatement(element: AstNode | undefined): element is GotoStatement {
1✔
119
    return element?.kind === AstNodeKind.GotoStatement;
2!
120
}
121
export function isLabelStatement(element: AstNode | undefined): element is LabelStatement {
1✔
122
    return element?.kind === AstNodeKind.LabelStatement;
2!
123
}
124
export function isReturnStatement(element: AstNode | undefined): element is ReturnStatement {
1✔
125
    return element?.kind === AstNodeKind.ReturnStatement;
738!
126
}
127
export function isTernaryExpression(element: AstNode | undefined): element is TernaryExpression {
1✔
128
    return element?.constructor?.name === 'TernaryExpression';
15!
129
}
130
export function isNullCoalescingExpression(element: AstNode | undefined): element is NullCoalescingExpression {
1✔
131
    return element?.constructor?.name === 'NullCoalescingExpression';
10!
132
}
133
export function isEndStatement(element: AstNode | undefined): element is EndStatement {
1✔
134
    return element?.kind === AstNodeKind.EndStatement;
2!
135
}
136
export function isStopStatement(element: AstNode | undefined): element is StopStatement {
1✔
137
    return element?.kind === AstNodeKind.StopStatement;
2!
138
}
139
export function isForStatement(element: AstNode | undefined): element is ForStatement {
1✔
140
    return element?.kind === AstNodeKind.ForStatement;
164✔
141
}
142
export function isForEachStatement(element: AstNode | undefined): element is ForEachStatement {
1✔
143
    return element?.kind === AstNodeKind.ForEachStatement;
273✔
144
}
145
export function isWhileStatement(element: AstNode | undefined): element is WhileStatement {
1✔
146
    return element?.kind === AstNodeKind.WhileStatement;
152✔
147
}
148
export function isDimStatement(element: AstNode | undefined): element is DimStatement {
1✔
149
    return element?.constructor?.name === 'DimStatement';
8!
150
}
151
export function isDottedSetStatement(element: AstNode | undefined): element is DottedSetStatement {
1✔
152
    return element?.kind === AstNodeKind.DottedSetStatement;
297!
153
}
154
export function isIndexedSetStatement(element: AstNode | undefined): element is IndexedSetStatement {
1✔
155
    return element?.kind === AstNodeKind.IndexedSetStatement;
291!
156
}
157
export function isLibraryStatement(element: AstNode | undefined): element is LibraryStatement {
1✔
158
    return element?.kind === AstNodeKind.LibraryStatement;
4,844!
159
}
160
export function isNamespaceStatement(element: AstNode | undefined): element is NamespaceStatement {
1✔
161
    return element?.kind === AstNodeKind.NamespaceStatement;
219,086✔
162
}
163
export function isClassStatement(element: AstNode | undefined): element is ClassStatement {
1✔
164
    return element?.kind === AstNodeKind.ClassStatement;
14,156!
165
}
166
export function isImportStatement(element: AstNode | undefined): element is ImportStatement {
1✔
167
    return element?.kind === AstNodeKind.ImportStatement;
5,238!
168
}
169
export function isMethodStatement(element: AstNode | undefined): element is MethodStatement {
1✔
170
    return element?.kind === AstNodeKind.MethodStatement;
13,174✔
171
}
172
export function isFieldStatement(element: AstNode | undefined): element is FieldStatement {
1✔
173
    return element?.kind === AstNodeKind.FieldStatement;
1,486✔
174
}
175
export function isInterfaceStatement(element: AstNode | undefined): element is InterfaceStatement {
1✔
176
    return element?.kind === AstNodeKind.InterfaceStatement;
4,469!
177
}
178
export function isInterfaceMethodStatement(element: AstNode | undefined): element is InterfaceMethodStatement {
1✔
179
    return element?.kind === AstNodeKind.InterfaceMethodStatement;
4,876✔
180
}
181
export function isInterfaceFieldStatement(element: AstNode | undefined): element is InterfaceFieldStatement {
1✔
182
    return element?.kind === AstNodeKind.InterfaceFieldStatement;
344!
183
}
184
export function isMemberField(element: AstNode | undefined): element is InterfaceFieldStatement | FieldStatement {
1✔
185
    return isFieldStatement(element) || isInterfaceFieldStatement(element);
73✔
186
}
187
export function isMemberMethod(element: AstNode | undefined): element is InterfaceMethodStatement | MethodStatement {
1✔
UNCOV
188
    return isMethodStatement(element) || isInterfaceMethodStatement(element);
×
189
}
190

191
export function isEnumStatement(element: AstNode | undefined): element is EnumStatement {
1✔
192
    return element?.kind === AstNodeKind.EnumStatement;
819!
193
}
194
export function isEnumMemberStatement(element: AstNode | undefined): element is EnumMemberStatement {
1✔
195
    return element?.kind === AstNodeKind.EnumMemberStatement;
866!
196
}
197
export function isConstStatement(element: AstNode | undefined): element is ConstStatement {
1✔
198
    return element?.kind === AstNodeKind.ConstStatement;
6,177✔
199
}
200
export function isContinueStatement(element: AstNode | undefined): element is ContinueStatement {
1✔
201
    return element?.kind === AstNodeKind.ContinueStatement;
27!
202
}
203
export function isTryCatchStatement(element: AstNode | undefined): element is TryCatchStatement {
1✔
204
    return element?.kind === AstNodeKind.TryCatchStatement;
138✔
205
}
206
export function isCatchStatement(element: AstNode | undefined): element is CatchStatement {
1✔
207
    return element?.kind === AstNodeKind.CatchStatement;
131✔
208
}
209
export function isThrowStatement(element: AstNode | undefined): element is ThrowStatement {
1✔
210
    return element?.kind === AstNodeKind.ThrowStatement;
6!
211
}
212
export function isConditionalCompileStatement(element: AstNode | undefined): element is ConditionalCompileStatement {
1✔
213
    return element?.kind === AstNodeKind.ConditionalCompileStatement;
4,802✔
214
}
215
export function isConditionalCompileConstStatement(element: AstNode | undefined): element is ConditionalCompileConstStatement {
1✔
216
    return element?.kind === AstNodeKind.ConditionalCompileConstStatement;
68!
217
}
218
export function isConditionalCompileErrorStatement(element: AstNode | undefined): element is ConditionalCompileErrorStatement {
1✔
219
    return element?.kind === AstNodeKind.ConditionalCompileErrorStatement;
64!
220
}
221
export function isAugmentedAssignmentStatement(element: AstNode | undefined): element is AugmentedAssignmentStatement {
1✔
222
    return element?.kind === AstNodeKind.AugmentedAssignmentStatement;
29!
223
}
224
export function isTypecastStatement(element: AstNode | undefined): element is TypecastStatement {
1✔
225
    return element?.constructor?.name === 'TypecastStatement';
7,961✔
226
}
227
export function isAliasStatement(element: AstNode | undefined): element is AliasStatement {
1✔
228
    return element?.constructor?.name === 'AliasStatement';
96,283✔
229
}
230
export function isTypeStatement(element: AstNode | undefined): element is TypeStatement {
1✔
231
    return element?.constructor?.name === 'TypeStatement';
3,659!
232
}
233

234
// Expressions reflection
235
/**
236
 * Determine if the variablvalue is a descendent of the Expression base class.
237
 * Due to performance restrictions, this expects all statements to directly extend Expression,
238
 * so it only checks the immediate parent's class name. For example:
239
 * this will work for StringLiteralExpression -> Expression,
240
 * but will not work CustomStringLiteralExpression -> StringLiteralExpression -> Expression
241
 */
242
export function isExpression(element: AstNode | undefined): element is Expression {
1✔
243
    // eslint-disable-next-line no-bitwise
244
    return !!(element && element.visitMode & InternalWalkMode.visitExpressions);
223✔
245
}
246

247
export function isBinaryExpression(element: AstNode | undefined): element is BinaryExpression {
1✔
248
    return element?.kind === AstNodeKind.BinaryExpression;
32,787!
249
}
250
export function isCallExpression(element: AstNode | undefined): element is CallExpression {
1✔
251
    return element?.kind === AstNodeKind.CallExpression;
51,190✔
252
}
253
export function isFunctionExpression(element: AstNode | undefined): element is FunctionExpression {
1✔
254
    return element?.kind === AstNodeKind.FunctionExpression;
81,616✔
255
}
256
export function isDottedGetExpression(element: AstNode | undefined): element is DottedGetExpression {
1✔
257
    return element?.kind === AstNodeKind.DottedGetExpression;
60,291✔
258
}
259
export function isXmlAttributeGetExpression(element: AstNode | undefined): element is XmlAttributeGetExpression {
1✔
260
    return element?.kind === AstNodeKind.XmlAttributeGetExpression;
13,384!
261
}
262
export function isIndexedGetExpression(element: AstNode | undefined): element is IndexedGetExpression {
1✔
263
    return element?.kind === AstNodeKind.IndexedGetExpression;
14,154!
264
}
265
export function isGroupingExpression(element: AstNode | undefined): element is GroupingExpression {
1✔
266
    return element?.kind === AstNodeKind.GroupingExpression;
1,983!
267
}
268
export function isLiteralExpression(element: AstNode | undefined): element is LiteralExpression {
1✔
269
    return element?.kind === AstNodeKind.LiteralExpression;
2,913✔
270
}
271
export function isEscapedCharCodeLiteralExpression(element: AstNode | undefined): element is EscapedCharCodeLiteralExpression {
1✔
272
    return element?.kind === AstNodeKind.EscapedCharCodeLiteralExpression;
19!
273
}
274
export function isArrayLiteralExpression(element: AstNode | undefined): element is ArrayLiteralExpression {
1✔
275
    return element?.kind === AstNodeKind.ArrayLiteralExpression;
23!
276
}
277
export function isAALiteralExpression(element: AstNode | undefined): element is AALiteralExpression {
1✔
278
    return element?.kind === AstNodeKind.AALiteralExpression;
25!
279
}
280
export function isAAMemberExpression(element: AstNode | undefined): element is AAMemberExpression {
1✔
281
    return element?.kind === AstNodeKind.AAMemberExpression;
635!
282
}
283
export function isUnaryExpression(element: AstNode | undefined): element is UnaryExpression {
1✔
284
    return element?.kind === AstNodeKind.UnaryExpression;
12,036✔
285
}
286
export function isVariableExpression(element: AstNode | undefined): element is VariableExpression {
1✔
287
    return element?.kind === AstNodeKind.VariableExpression;
35,642✔
288
}
289
export function isSourceLiteralExpression(element: AstNode | undefined): element is SourceLiteralExpression {
1✔
290
    return element?.kind === AstNodeKind.SourceLiteralExpression;
2!
291
}
292
export function isNewExpression(element: AstNode | undefined): element is NewExpression {
1✔
293
    return element?.kind === AstNodeKind.NewExpression;
18,860!
294
}
295
export function isCallfuncExpression(element: AstNode | undefined): element is CallfuncExpression {
1✔
296
    return element?.kind === AstNodeKind.CallfuncExpression;
22,890!
297
}
298
export function isTemplateStringQuasiExpression(element: AstNode | undefined): element is TemplateStringQuasiExpression {
1✔
299
    return element?.kind === AstNodeKind.TemplateStringQuasiExpression;
14!
300
}
301
export function isTemplateStringExpression(element: AstNode | undefined): element is TemplateStringExpression {
1✔
302
    return element?.kind === AstNodeKind.TemplateStringExpression;
26!
303
}
304
export function isTaggedTemplateStringExpression(element: AstNode | undefined): element is TaggedTemplateStringExpression {
1✔
305
    return element?.kind === AstNodeKind.TaggedTemplateStringExpression;
22!
306
}
307
export function isFunctionParameterExpression(element: AstNode | undefined): element is FunctionParameterExpression {
1✔
308
    return element?.kind === AstNodeKind.FunctionParameterExpression;
31,797✔
309
}
310
export function isAnnotationExpression(element: AstNode | undefined): element is AnnotationExpression {
1✔
311
    return element?.kind === AstNodeKind.AnnotationExpression;
70,206!
312
}
313
export function isTypedefProvider(element: any): element is TypedefProvider {
1✔
314
    return 'getTypedef' in element;
118✔
315
}
316
export function isTypeExpression(element: any): element is TypeExpression {
1✔
317
    return element?.kind === AstNodeKind.TypeExpression;
59,251!
318
}
319
export function isTypecastExpression(element: any): element is TypecastExpression {
1✔
320
    return element?.kind === AstNodeKind.TypecastExpression;
49!
321
}
322
export function isTypedArrayExpression(element: any): element is TypedArrayExpression {
1✔
323
    return element?.kind === AstNodeKind.TypedArrayExpression;
30,722!
324
}
325
export function isPrintSeparatorExpression(element: any): element is PrintSeparatorExpression {
1✔
326
    return element?.kind === AstNodeKind.PrintSeparatorExpression;
72!
327
}
328
export function isInlineInterfaceExpression(element: any): element is InlineInterfaceExpression {
1✔
329
    return element?.kind === AstNodeKind.InlineInterfaceExpression;
4!
330
}
331
export function isInlineInterfaceMemberExpression(element: any): element is InlineInterfaceMemberExpression {
1✔
UNCOV
332
    return element?.kind === AstNodeKind.InlineInterfaceMemberExpression;
×
333
}
334

335
// BscType reflection
336
export function isStringType(value: any): value is StringType {
1✔
337
    return value?.kind === BscTypeKind.StringType;
765,477!
338
}
339
export function isRoStringType(value: any): value is InterfaceType {
1✔
340
    return isBuiltInType(value, 'roString');
1,894✔
341
}
342
export function isStringTypeLike(value: any): value is StringType | InterfaceType {
1✔
343
    return isStringType(value) || isRoStringType(value) || isComplexTypeOf(value, isStringTypeLike);
3,863✔
344
}
345

346
export function isTypedFunctionType(value: any): value is TypedFunctionType {
1✔
347
    return value?.kind === BscTypeKind.TypedFunctionType;
774,718✔
348
}
349

350
export function isFunctionType(value: any): value is FunctionType {
1✔
351
    return value?.kind === BscTypeKind.FunctionType;
770,543✔
352
}
353
export function isRoFunctionType(value: any): value is InterfaceType {
1✔
354
    return value?.kind === BscTypeKind.RoFunctionType || isBuiltInType(value, 'roFunction');
770,476✔
355
}
356
export function isFunctionTypeLike(value: any): value is FunctionType | InterfaceType {
1✔
357
    return isFunctionType(value) || isRoFunctionType(value) || isComplexTypeOf(value, isFunctionTypeLike);
770,543✔
358
}
359

360
export function isBooleanType(value: any): value is BooleanType {
1✔
361
    return value?.kind === BscTypeKind.BooleanType;
764,275!
362
}
363
export function isRoBooleanType(value: any): value is InterfaceType {
1✔
364
    return isBuiltInType(value, 'roBoolean');
1,987✔
365
}
366
export function isBooleanTypeLike(value: any): value is BooleanType | InterfaceType {
1✔
367
    return isBooleanType(value) || isRoBooleanType(value) || isComplexTypeOf(value, isBooleanTypeLike);
2,136✔
368
}
369

370
export function isIntegerType(value: any): value is IntegerType {
1✔
371
    return value?.kind === BscTypeKind.IntegerType;
767,654!
372
}
373
export function isRoIntType(value: any): value is LongIntegerType {
1✔
374
    return isBuiltInType(value, 'roInt');
3,104✔
375
}
376
export function isIntegerTypeLike(value: any): value is IntegerType | InterfaceType {
1✔
377
    return isIntegerType(value) || isRoIntType(value) || isComplexTypeOf(value, isIntegerTypeLike);
5,559✔
378
}
379

380
export function isLongIntegerType(value: any): value is LongIntegerType {
1✔
381
    return value?.kind === BscTypeKind.LongIntegerType;
765,725!
382
}
383
export function isRoLongIntegerType(value: any): value is InterfaceType {
1✔
384
    return isBuiltInType(value, 'roLongInteger');
4,218✔
385
}
386
export function isLongIntegerTypeLike(value: any): value is LongIntegerType | InterfaceType {
1✔
387
    return isLongIntegerType(value) || isRoLongIntegerType(value) || isComplexTypeOf(value, isLongIntegerTypeLike);
4,408✔
388
}
389

390
export function isFloatType(value: any): value is FloatType {
1✔
391
    return value?.kind === BscTypeKind.FloatType;
765,710!
392
}
393
export function isRoFloatType(value: any): value is InterfaceType {
1✔
394
    return isBuiltInType(value, 'roFloat');
3,906✔
395
}
396
export function isFloatTypeLike(value: any): value is FloatType | InterfaceType {
1✔
397
    return isFloatType(value) || isRoFloatType(value) || isComplexTypeOf(value, isFloatTypeLike);
4,449✔
398
}
399

400
export function isDoubleType(value: any): value is DoubleType {
1✔
401
    return value?.kind === BscTypeKind.DoubleType;
765,047!
402
}
403
export function isRoDoubleType(value: any): value is InterfaceType {
1✔
404
    return isBuiltInType(value, 'roDouble');
3,817✔
405
}
406
export function isDoubleTypeLike(value: any): value is DoubleType | InterfaceType {
1✔
407
    return isDoubleType(value) || isRoDoubleType(value) || isComplexTypeOf(value, isDoubleTypeLike);
3,882✔
408
}
409

410
export function isInvalidType(value: any): value is InvalidType {
1✔
411
    return value?.kind === BscTypeKind.InvalidType;
769,155✔
412
}
413
export function isRoInvalidType(value: any): value is InterfaceType {
1✔
414
    return isBuiltInType(value, 'roInvalid');
1,548✔
415
}
416
export function isInvalidTypeLike(value: any): value is InvalidType | InterfaceType {
1✔
417
    return isInvalidType(value) || isRoInvalidType(value) || isComplexTypeOf(value, isInvalidTypeLike);
1,610✔
418
}
419

420
export function isVoidType(value: any): value is VoidType {
1✔
421
    return value?.kind === BscTypeKind.VoidType;
257,794✔
422
}
423
export function isClassType(value: any): value is ClassType {
1✔
424
    return value?.kind === BscTypeKind.ClassType;
37,579✔
425
}
426
export function isComponentType(value: any): value is ComponentType {
1✔
427
    return value?.kind === BscTypeKind.ComponentType;
243,285✔
428
}
429
export function isDynamicType(value: any): value is DynamicType {
1✔
430
    return value?.kind === BscTypeKind.DynamicType;
1,019,461✔
431
}
432
export function isInterfaceType(value: any): value is InterfaceType {
1✔
433
    return value?.kind === BscTypeKind.InterfaceType;
1,546,878✔
434
}
435
export function isObjectType(value: any): value is ObjectType {
1✔
436
    return value?.kind === BscTypeKind.ObjectType;
765,621✔
437
}
438
export function isReferenceType(value: any): value is ReferenceType {
1✔
439
    return value?.__reflection?.name === 'ReferenceType';
510,840✔
440
}
441
export function isEnumType(value: any): value is EnumType {
1✔
442
    return value?.kind === BscTypeKind.EnumType;
5,908✔
443
}
444
export function isEnumMemberType(value: any): value is EnumMemberType {
1✔
445
    return value?.kind === BscTypeKind.EnumMemberType;
760,138!
446
}
447
export function isTypePropertyReferenceType(value: any): value is TypePropertyReferenceType {
1✔
448
    return value?.__reflection?.name === 'TypePropertyReferenceType';
980!
449
}
450
export function isBinaryOperatorReferenceType(value: any): value is BinaryOperatorReferenceType {
1✔
451
    return value?.__reflection?.name === 'BinaryOperatorReferenceType';
6!
452
}
453
export function isArrayDefaultTypeReferenceType(value: any): value is ArrayDefaultTypeReferenceType {
1✔
454
    return value?.__reflection?.name === 'ArrayDefaultTypeReferenceType';
953!
455
}
456
export function isParamTypeFromValueReferenceType(value: any): value is ParamTypeFromValueReferenceType {
1✔
UNCOV
457
    return value?.__reflection?.name === 'ParamTypeFromValueReferenceType';
×
458
}
459
export function isNamespaceType(value: any): value is NamespaceType {
1✔
460
    return value?.kind === BscTypeKind.NamespaceType;
17,717✔
461
}
462
export function isUnionType(value: any): value is UnionType {
1✔
463
    return value?.kind === BscTypeKind.UnionType;
1,339,704✔
464
}
465
export function isIntersectionType(value: any): value is IntersectionType {
1✔
466
    return value?.kind === BscTypeKind.IntersectionType;
289,873!
467
}
468
export function isUninitializedType(value: any): value is UninitializedType {
1✔
469
    return value?.kind === BscTypeKind.UninitializedType;
2,585✔
470
}
471
export function isArrayType(value: any): value is ArrayType {
1✔
472
    return value?.kind === BscTypeKind.ArrayType;
761,720✔
473
}
474
export function isAssociativeArrayType(value: any): value is AssociativeArrayType {
1✔
475
    return value?.kind === BscTypeKind.AssociativeArrayType;
755,581✔
476
}
477
export function isTypeStatementType(value: any): value is TypeStatementType {
1✔
478
    return value?.kind === BscTypeKind.TypeStatementType;
1,584,007✔
479
}
480

481
export function isInheritableType(target): target is InheritableType {
1✔
482
    return isClassType(target) || isCallFuncableType(target);
4,151✔
483
}
484

485
export function isCallFuncableType(target): target is CallFuncableType {
1✔
486
    return isInterfaceType(target) || isComponentType(target) || isComplexTypeOf(target, isCallFuncableType);
3,893✔
487
}
488

489
export function isCallableType(target): target is BaseFunctionType {
1✔
490
    return isFunctionTypeLike(target) || isTypedFunctionType(target) || isObjectType(target) || (isDynamicType(target) && !isAnyReferenceType(target));
770,514✔
491
}
492

493
export function isAnyReferenceType(target): target is AnyReferenceType {
1✔
494
    const name = target?.__reflection?.name;
2,299,631✔
495
    return name === 'ReferenceType' || name === 'TypePropertyReferenceType' || name === 'BinaryOperatorReferenceType' || name === 'ArrayDefaultTypeReferenceType' || name === 'ParamTypeFromValueReferenceType';
2,299,631✔
496
}
497

498
export function isNumberType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | InterfaceType {
1✔
499
    return isIntegerType(value) ||
2,037✔
500
        isLongIntegerType(value) ||
501
        isFloatType(value) ||
502
        isDoubleType(value);
503
}
504

505
export function isNumberTypeLike(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | InterfaceType {
1✔
506
    return isIntegerTypeLike(value) ||
4,988✔
507
        isLongIntegerTypeLike(value) ||
508
        isFloatTypeLike(value) ||
509
        isDoubleTypeLike(value) ||
510
        isComplexTypeOf(value, isNumberTypeLike);
511
}
512

513
export function isPrimitiveType(value: any = false): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | InterfaceType {
1✔
514
    return isNumberType(value) ||
2,016✔
515
        isBooleanType(value) ||
516
        isStringType(value);
517
}
518

519
export function isPrimitiveTypeLike(value: any = false): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | InterfaceType {
1!
UNCOV
520
    return isNumberTypeLike(value) ||
×
521
        isBooleanTypeLike(value) ||
522
        isStringTypeLike(value) ||
523
        isTypeStatementTypeOf(value, isPrimitiveTypeLike);
524
}
525

526
export function isBuiltInType(value: any, name: string): value is InterfaceType {
1✔
527
    return (isInterfaceType(value) && value.name.toLowerCase() === name.toLowerCase() && value.isBuiltIn) ||
786,912✔
528
        (isTypeStatementType(value) && isBuiltInType(value.wrappedType, name));
529
}
530

531
const nativeTypeKinds = [
1✔
532
    BscTypeKind.DynamicType,
533
    BscTypeKind.ObjectType,
534
    BscTypeKind.VoidType,
535
    BscTypeKind.FunctionType
536
];
537
export function isNativeType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | StringType | BooleanType | VoidType | DynamicType | ObjectType | FunctionType | InterfaceType {
1✔
538
    return isPrimitiveType(value) || nativeTypeKinds.includes(value?.kind);
324✔
539
}
540

541
export function isTypeStatementTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
542
    return isTypeStatementType(value) && typeGuard(value.wrappedType);
791,592✔
543
}
544

545
export function isUnionTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
546
    return isUnionType(value) && value.types.every(typeGuard);
791,565✔
547
}
548

549
export function isComplexTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
550
    // TODO: add more complex type checks as needed, like IntersectionType
551
    return isTypeStatementTypeOf(value, typeGuard) ||
791,592✔
552
        isUnionTypeOf(value, typeGuard);
553
}
554

555

556
export function isComplexType(value: any): value is UnionType | IntersectionType {
1✔
557
    return isUnionType(value) || isIntersectionType(value);
53✔
558
}
559

560
// Literal reflection
561

562
export function isLiteralInvalid(value: any): value is LiteralExpression & { type: InvalidType } {
1✔
563
    return isLiteralExpression(value) && value.tokens.value.kind === TokenKind.Invalid;
6✔
564
}
565
export function isLiteralBoolean(value: any): value is LiteralExpression & { type: BooleanType } {
1✔
566
    return isLiteralExpression(value) && isBooleanType(value.getType());
37✔
567
}
568
export function isLiteralString(value: any): value is LiteralExpression & { type: StringType } {
1✔
569
    return isLiteralExpression(value) && isStringType(value.getType());
236✔
570
}
571
export function isLiteralNumber(value: any): value is LiteralExpression & { type: IntegerType | LongIntegerType | FloatType | DoubleType } {
1✔
572
    return isLiteralExpression(value) && isNumberType(value.getType());
32✔
573
}
574
export function isLiteralInteger(value: any): value is LiteralExpression & { type: IntegerType } {
1✔
575
    return isLiteralExpression(value) && isIntegerType(value.getType());
5✔
576
}
577
export function isLiteralLongInteger(value: any): value is LiteralExpression & { type: LongIntegerType } {
1✔
578
    return isLiteralExpression(value) && isLongIntegerType(value.getType());
5✔
579
}
580
export function isLiteralFloat(value: any): value is LiteralExpression & { type: FloatType } {
1✔
581
    return isLiteralExpression(value) && isFloatType(value.getType());
5✔
582
}
583
export function isLiteralDouble(value: any): value is LiteralExpression & { type: DoubleType } {
1✔
584
    return isLiteralExpression(value) && isDoubleType(value.getType());
5✔
585
}
586

587
// Diagnostics
588
export function isBsDiagnostic(value: any): value is BsDiagnostic {
1✔
589
    return value.message;
1,498✔
590
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc