How to use the isFunctionExpression function from typescript

Find comprehensive JavaScript typescript.isFunctionExpression code examples handpicked from public code repositorys.

typescript.isFunctionExpression is a function that checks whether a given AST node is a function expression or not.

169
170
171
172
173
174
175
176
177
178
    return false
  }
}

const isArrowFunction = ts.isArrowFunction(node)
const isFunctionExpression = ts.isFunctionExpression(node)
// const isFunctionLike = ts.isFunctionLike(node)
const isVariFunctionNode = isVariableFunction(node)

if (isVariFunctionNode !== false) {
fork icon23
star icon78
watch icon1

+ 3 other calls in file

How does typescript.isFunctionExpression work?

typescript.isFunctionExpression is a function provided by the TypeScript compiler API that checks whether a given node is a function expression node. In more detail, it takes a TypeScript Node object as input and returns a boolean value indicating whether the node represents a function expression. A function expression is a syntactic construct in JavaScript that defines an anonymous function and returns it as a value, which can be assigned to a variable or passed as an argument to another function. typescript.isFunctionExpression checks if the given node has a type of SyntaxKind.FunctionExpression, which represents a function expression node in the TypeScript abstract syntax tree.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import ts from "typescript";

const code = "const sum = (a, b) => a + b;";
const sourceFile = ts.createSourceFile(
  "sample.ts",
  code,
  ts.ScriptTarget.ES2020,
  true
);

ts.forEachChild(sourceFile, (node) => {
  if (
    ts.isVariableDeclaration(node) &&
    ts.isFunctionExpression(node.initializer)
  ) {
    console.log("This is a variable declaration with a function expression");
  }
});

In this example, the typescript.isFunctionExpression function is used to check if a given node is a function expression. The ts.isVariableDeclaration function is used to check if the node is a variable declaration, and the ts.isFunctionExpression function is used to check if the initializer of the variable declaration is a function expression. If both conditions are true, the console will log "This is a variable declaration with a function expression".

Other functions in typescript

Sorted by popularity

function icon

typescript.SyntaxKind is the most popular function in typescript (82777 examples)