How to use the createCall function from typescript

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

typescript.createCall is a method provided by the TypeScript compiler API to create a new CallExpression node.

396
397
398
399
400
401
402
403
404
405
...(augmentations && augmentations.length ? [wrapInDeclareGlobal(augmentations)] : []),
...(hasTLA
    ? // If there is a top-level await, wrap all non-hoisted statements in (async () => { ... })();
    [
        ts.createExpressionStatement(
            ts.createCall(
                ts.createArrowFunction(
                    [
                        ts.createModifier(
                            ts.SyntaxKind.AsyncKeyword
fork icon116
star icon294
watch icon29

How does typescript.createCall work?

typescript.createCall is a function provided by the TypeScript compiler API that creates an AST node representing a function call expression in the parsed TypeScript source code. The function takes in the expression that represents the function being called, as well as an array of arguments that are passed to the function, and returns a CallExpression AST node.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
import ts from "typescript";

// create the arguments for the call
const args = [ts.createStringLiteral("hello")];

// create the call expression
const callExpr = ts.createCall(
  ts.createIdentifier("console.log"),
  undefined,
  args
);

console.log(callExpr.getText()); // prints "console.log("hello")"

In this example, we use typescript.createCall to create a call expression for the console.log function with a single string argument of 'hello'. We then print the resulting expression using getText().

Other functions in typescript

Sorted by popularity

function icon

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