Created
May 10, 2023 12:11
-
-
Save TomasKostadinov/0284220e001b6822e842e4a71ff732aa to your computer and use it in GitHub Desktop.
Find out what type of typescript-node your current node is
This file contains 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
import * as ts from 'typescript'; | |
function whatTypeOfNodeIsIt(node: ts.Node) { | |
const functions = [ | |
ts.isNumericLiteral, | |
ts.isBigIntLiteral, | |
ts.isStringLiteral, | |
ts.isJsxText, | |
ts.isRegularExpressionLiteral, | |
ts.isNoSubstitutionTemplateLiteral, | |
ts.isTemplateHead, | |
ts.isTemplateMiddle, | |
ts.isTemplateTail, | |
ts.isDotDotDotToken, | |
ts.isPlusToken, | |
ts.isMinusToken, | |
ts.isAsteriskToken, | |
ts.isIdentifier, | |
ts.isPrivateIdentifier, | |
ts.isQualifiedName, | |
ts.isComputedPropertyName, | |
ts.isTypeParameterDeclaration, | |
ts.isParameter, | |
ts.isDecorator, | |
ts.isPropertySignature, | |
ts.isPropertyDeclaration, | |
ts.isMethodSignature, | |
ts.isMethodDeclaration, | |
ts.isClassStaticBlockDeclaration, | |
ts.isConstructorDeclaration, | |
ts.isGetAccessorDeclaration, | |
ts.isSetAccessorDeclaration, | |
ts.isCallSignatureDeclaration, | |
ts.isConstructSignatureDeclaration, | |
ts.isIndexSignatureDeclaration, | |
ts.isTypePredicateNode, | |
ts.isTypeReferenceNode, | |
ts.isFunctionTypeNode, | |
ts.isConstructorTypeNode, | |
ts.isTypeQueryNode, | |
ts.isTypeLiteralNode, | |
ts.isArrayTypeNode, | |
ts.isTupleTypeNode, | |
ts.isNamedTupleMember, | |
ts.isOptionalTypeNode, | |
ts.isRestTypeNode, | |
ts.isUnionTypeNode, | |
ts.isIntersectionTypeNode, | |
ts.isConditionalTypeNode, | |
ts.isInferTypeNode, | |
ts.isParenthesizedTypeNode, | |
ts.isThisTypeNode, | |
ts.isTypeOperatorNode, | |
ts.isIndexedAccessTypeNode, | |
ts.isMappedTypeNode, | |
ts.isLiteralTypeNode, | |
ts.isImportTypeNode, | |
ts.isTemplateLiteralTypeSpan, | |
ts.isTemplateLiteralTypeNode, | |
ts.isObjectBindingPattern, | |
ts.isArrayBindingPattern, | |
ts.isBindingElement, | |
ts.isArrayLiteralExpression, | |
ts.isObjectLiteralExpression, | |
ts.isPropertyAccessExpression, | |
ts.isElementAccessExpression, | |
ts.isCallExpression, | |
ts.isNewExpression, | |
ts.isTaggedTemplateExpression, | |
ts.isTypeAssertionExpression, | |
ts.isParenthesizedExpression, | |
ts.isFunctionExpression, | |
ts.isArrowFunction, | |
ts.isDeleteExpression, | |
ts.isTypeOfExpression, | |
ts.isVoidExpression, | |
ts.isAwaitExpression, | |
ts.isPrefixUnaryExpression, | |
ts.isPostfixUnaryExpression, | |
ts.isBinaryExpression, | |
ts.isConditionalExpression, | |
ts.isTemplateExpression, | |
ts.isYieldExpression, | |
ts.isSpreadElement, | |
ts.isClassExpression, | |
ts.isOmittedExpression, | |
ts.isExpressionWithTypeArguments, | |
ts.isAsExpression, | |
ts.isSatisfiesExpression, | |
ts.isNonNullExpression, | |
ts.isMetaProperty, | |
ts.isSyntheticExpression, | |
ts.isPartiallyEmittedExpression, | |
ts.isCommaListExpression, | |
ts.isTemplateSpan, | |
ts.isSemicolonClassElement, | |
ts.isBlock, | |
ts.isVariableStatement, | |
ts.isEmptyStatement, | |
ts.isExpressionStatement, | |
ts.isIfStatement, | |
ts.isDoStatement, | |
ts.isWhileStatement, | |
ts.isForStatement, | |
ts.isForInStatement, | |
ts.isForOfStatement, | |
ts.isContinueStatement, | |
ts.isBreakStatement, | |
ts.isReturnStatement, | |
ts.isWithStatement, | |
ts.isSwitchStatement, | |
ts.isLabeledStatement, | |
ts.isThrowStatement, | |
ts.isTryStatement, | |
ts.isDebuggerStatement, | |
ts.isVariableDeclaration, | |
ts.isVariableDeclarationList, | |
ts.isFunctionDeclaration, | |
ts.isClassDeclaration, | |
ts.isInterfaceDeclaration, | |
ts.isTypeAliasDeclaration, | |
ts.isEnumDeclaration, | |
ts.isModuleDeclaration, | |
ts.isModuleBlock, | |
ts.isCaseBlock, | |
ts.isNamespaceExportDeclaration, | |
ts.isImportEqualsDeclaration, | |
ts.isImportDeclaration, | |
ts.isImportClause, | |
ts.isImportTypeAssertionContainer, | |
ts.isAssertClause, | |
ts.isAssertEntry, | |
ts.isNamespaceImport, | |
ts.isNamespaceExport, | |
ts.isNamedImports, | |
ts.isImportSpecifier, | |
ts.isExportAssignment, | |
ts.isExportDeclaration, | |
ts.isNamedExports, | |
ts.isExportSpecifier, | |
ts.isMissingDeclaration, | |
ts.isNotEmittedStatement, | |
ts.isExternalModuleReference, | |
ts.isJsxElement, | |
ts.isJsxSelfClosingElement, | |
ts.isJsxOpeningElement, | |
ts.isJsxClosingElement, | |
ts.isJsxFragment, | |
ts.isJsxOpeningFragment, | |
ts.isJsxClosingFragment, | |
ts.isJsxAttribute, | |
ts.isJsxAttributes, | |
ts.isJsxSpreadAttribute, | |
ts.isJsxExpression, | |
ts.isCaseClause, | |
ts.isDefaultClause, | |
ts.isHeritageClause, | |
ts.isCatchClause, | |
ts.isPropertyAssignment, | |
ts.isShorthandPropertyAssignment, | |
ts.isSpreadAssignment, | |
ts.isEnumMember, | |
ts.isUnparsedPrepend, | |
ts.isSourceFile, | |
ts.isBundle, | |
ts.isUnparsedSource, | |
]; | |
functions.forEach((fn) => { | |
if (fn(node)) { | |
console.log(fn.name); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment