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

rokucommunity / brighterscript / #15062

08 Jan 2026 07:11PM UTC coverage: 87.293% (+0.2%) from 87.061%
#15062

push

web-flow
Merge d779db470 into 2ea4d2108

14409 of 17441 branches covered (82.62%)

Branch coverage included in aggregate %.

57 of 57 new or added lines in 12 files covered. (100.0%)

189 existing lines in 10 files now uncovered.

15102 of 16366 relevant lines covered (92.28%)

24219.67 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 { TypeStatementType } from '../types/TypeStatementType';
43

44

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

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

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

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

62

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

67

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

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

76

77
// Statements reflection
78

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

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

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

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

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

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

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

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

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

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

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

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

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

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

419
export function isVoidType(value: any): value is VoidType {
1✔
420
    return value?.kind === BscTypeKind.VoidType;
257,611✔
421
}
422
export function isClassType(value: any): value is ClassType {
1✔
423
    return value?.kind === BscTypeKind.ClassType;
37,542✔
424
}
425
export function isComponentType(value: any): value is ComponentType {
1✔
426
    return value?.kind === BscTypeKind.ComponentType;
243,151✔
427
}
428
export function isDynamicType(value: any): value is DynamicType {
1✔
429
    return value?.kind === BscTypeKind.DynamicType;
1,018,909✔
430
}
431
export function isInterfaceType(value: any): value is InterfaceType {
1✔
432
    return value?.kind === BscTypeKind.InterfaceType;
1,546,064✔
433
}
434
export function isObjectType(value: any): value is ObjectType {
1✔
435
    return value?.kind === BscTypeKind.ObjectType;
765,272✔
436
}
437
export function isReferenceType(value: any): value is ReferenceType {
1✔
438
    return value?.__reflection?.name === 'ReferenceType';
510,404✔
439
}
440
export function isEnumType(value: any): value is EnumType {
1✔
441
    return value?.kind === BscTypeKind.EnumType;
5,909✔
442
}
443
export function isEnumMemberType(value: any): value is EnumMemberType {
1✔
444
    return value?.kind === BscTypeKind.EnumMemberType;
759,777!
445
}
446
export function isTypePropertyReferenceType(value: any): value is TypePropertyReferenceType {
1✔
447
    return value?.__reflection?.name === 'TypePropertyReferenceType';
906!
448
}
449
export function isBinaryOperatorReferenceType(value: any): value is BinaryOperatorReferenceType {
1✔
450
    return value?.__reflection?.name === 'BinaryOperatorReferenceType';
6!
451
}
452
export function isArrayDefaultTypeReferenceType(value: any): value is ArrayDefaultTypeReferenceType {
1✔
453
    return value?.__reflection?.name === 'ArrayDefaultTypeReferenceType';
879!
454
}
455
export function isParamTypeFromValueReferenceType(value: any): value is ParamTypeFromValueReferenceType {
1✔
UNCOV
456
    return value?.__reflection?.name === 'ParamTypeFromValueReferenceType';
×
457
}
458
export function isNamespaceType(value: any): value is NamespaceType {
1✔
459
    return value?.kind === BscTypeKind.NamespaceType;
17,703✔
460
}
461
export function isUnionType(value: any): value is UnionType {
1✔
462
    return value?.kind === BscTypeKind.UnionType;
1,052,006✔
463
}
464
export function isUninitializedType(value: any): value is UninitializedType {
1✔
465
    return value?.kind === BscTypeKind.UninitializedType;
2,581✔
466
}
467
export function isArrayType(value: any): value is ArrayType {
1✔
468
    return value?.kind === BscTypeKind.ArrayType;
761,347✔
469
}
470
export function isAssociativeArrayType(value: any): value is AssociativeArrayType {
1✔
471
    return value?.kind === BscTypeKind.AssociativeArrayType;
755,216✔
472
}
473
export function isTypeStatementType(value: any): value is TypeStatementType {
1✔
474
    return value?.kind === BscTypeKind.TypeStatementType;
1,585,954✔
475
}
476

477
export function isInheritableType(target): target is InheritableType {
1✔
478
    return isClassType(target) || isCallFuncableType(target) || isComplexTypeOf(target, isInheritableType);
4,130✔
479
}
480

481
export function isCallFuncableType(target): target is CallFuncableType {
1✔
482
    return isInterfaceType(target) || isComponentType(target) || isComplexTypeOf(target, isCallFuncableType);
3,872✔
483
}
484

485
export function isCallableType(target): target is BaseFunctionType {
1✔
486
    return isFunctionTypeLike(target) || isTypedFunctionType(target) || isObjectType(target) || (isDynamicType(target) && !isAnyReferenceType(target));
770,147✔
487
}
488

489
export function isAnyReferenceType(target): target is AnyReferenceType {
1✔
490
    const name = target?.__reflection?.name;
2,294,687✔
491
    return name === 'ReferenceType' || name === 'TypePropertyReferenceType' || name === 'BinaryOperatorReferenceType' || name === 'ArrayDefaultTypeReferenceType' || name === 'ParamTypeFromValueReferenceType';
2,294,687✔
492
}
493

494
export function isNumberType(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | InterfaceType {
1✔
495
    return isIntegerType(value) ||
2,037✔
496
        isLongIntegerType(value) ||
497
        isFloatType(value) ||
498
        isDoubleType(value);
499
}
500

501
export function isNumberTypeLike(value: any): value is IntegerType | LongIntegerType | FloatType | DoubleType | InterfaceType {
1✔
502
    return isIntegerTypeLike(value) ||
4,987✔
503
        isLongIntegerTypeLike(value) ||
504
        isFloatTypeLike(value) ||
505
        isDoubleTypeLike(value) ||
506
        isComplexTypeOf(value, isNumberTypeLike);
507
}
508

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

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

522
export function isBuiltInType(value: any, name: string): value is InterfaceType {
1✔
523
    return (isInterfaceType(value) && value.name.toLowerCase() === name.toLowerCase() && value.isBuiltIn) ||
786,496✔
524
        (isTypeStatementType(value) && isBuiltInType(value.wrappedType, name));
525
}
526

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

537
export function isTypeStatementTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
538
    return isTypeStatementType(value) && typeGuard(value.wrappedType);
793,955✔
539
}
540

541
export function isUnionTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
542
    return isUnionType(value) && value.types.every(typeGuard);
793,928✔
543
}
544

545
export function isComplexTypeOf(value: any, typeGuard: (val: any) => boolean) {
1✔
546
    // TODO: add more complex type checks as needed, like IntersectionType
547
    return isTypeStatementTypeOf(value, typeGuard) ||
793,955✔
548
        isUnionTypeOf(value, typeGuard);
549
}
550

551

552
// Literal reflection
553

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

579
// Diagnostics
580
export function isBsDiagnostic(value: any): value is BsDiagnostic {
1✔
581
    return value.message;
1,498✔
582
}
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

© 2026 Coveralls, Inc