Last active
July 17, 2025 01:16
-
-
Save souporserious/6e8ca25b30afb1b9895208b45e543cc2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Returns a list of the type's flags. */ | |
function typeIs(type: tsMorph.Type) { | |
return Object.entries({ | |
Anonymous: type.isAnonymous(), | |
Array: type.isArray(), | |
Boolean: type.isBoolean() || type.isBooleanLiteral(), | |
String: type.isString() || type.isStringLiteral(), | |
Number: type.isNumber() || type.isNumberLiteral(), | |
BigInt: type.isBigInt() || type.isBigIntLiteral(), | |
Symbol: isSymbolType(type), | |
Undefined: type.isUndefined(), | |
Void: type.isVoid(), | |
Object: type.isObject(), | |
Intersection: type.isIntersection(), | |
Union: type.isUnion(), | |
Literal: type.isLiteral(), | |
Tuple: type.isTuple(), | |
Unknown: type.isUnknown(), | |
Never: type.isNever(), | |
Any: type.isAny(), | |
Null: type.isNull(), | |
Interface: type.isInterface(), | |
Enum: type.isEnum() || type.isEnumLiteral(), | |
Reference: isReferenceType(type), | |
TypeParameter: type.isTypeParameter(), | |
MappedType: isMappedType(type), | |
IndexedAccess: isIndexedAccessType(type), | |
ConditionalType: isConditionalType(type), | |
}) | |
.filter((entry) => entry.at(1)) | |
.map((entry) => entry.at(0)) | |
.join(', ') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment