How to use the createReturn function from typescript

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

typescript.createReturn is a function that creates a return statement node for a given expression in TypeScript.

311
312
313
314
315
316
317
318
319
320
if (ts.isClassDeclaration(hostNode)) {
    updatedStatements[0] = ts.createClassDeclaration(hostNode.decorators, undefined, hostNode.name, hostNode.typeParameters, hostNode.heritageClauses, hostNode.members);
}
const pureIife = ast_utils_1.addPureComment(ts.createImmediatelyInvokedArrowFunction([
    ...updatedStatements,
    ts.createReturn(ts.createIdentifier(name)),
]));
const modifiers = hostNode.modifiers;
const isDefault = !!modifiers
    && modifiers.some(x => x.kind === ts.SyntaxKind.DefaultKeyword);
fork icon0
star icon0
watch icon1

+ 5 other calls in file

How does typescript.createReturn work?

typescript.createReturn is a function in the TypeScript compiler API that creates a return statement node representing the return keyword along with the expression to be returned. It takes an expression node and returns a ReturnStatement node.

Ai Example

1
2
3
4
import ts from "typescript";

// create a return statement node that returns the number 42
const returnStatement = ts.createReturn(ts.createLiteral(42));

This code will create a return statement node that returns the number 42.

Other functions in typescript

Sorted by popularity

function icon

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