How to use the createPropertyAccess function from typescript

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

typescript.createPropertyAccess is a function in the TypeScript compiler API that creates a syntax tree node representing a property access expression.

131
132
133
134
135
136
137
138
139
140
if (!url) {
    return null;
}
const urlLiteral = ts.createLiteral(url);
if (moduleKind < ts.ModuleKind.ES2015) {
    return ts.createPropertyAccess(ts.createCall(ts.createIdentifier('require'), [], [urlLiteral]), 'default');
}
else {
    const importName = ts.createIdentifier(`__NG_CLI_RESOURCE__${resourceImportDeclarations.length}`);
    resourceImportDeclarations.push(ts.createImportDeclaration(undefined, undefined, ts.createImportClause(importName, undefined), urlLiteral));
fork icon0
star icon0
watch icon1

How does typescript.createPropertyAccess work?

The typescript.createPropertyAccess function creates a syntax tree node that represents a property access expression, which accesses the specified property of the specified object.

The function takes two arguments:

  1. expression: A syntax tree node representing the object to access the property of.
  2. name: A string or syntax tree node representing the name of the property to access.

Ai Example

1
2
3
4
5
6
7
import * as ts from "typescript";

// Create an identifier node for the object
const objectIdentifier = ts.createIdentifier("myObject");

// Create a property access expression for the property 'myProperty'
const propertyAccess = ts.createPropertyAccess(objectIdentifier, "myProperty");

In this example, typescript.createPropertyAccess is used to create a property access expression for the property 'myProperty' of an object with identifier 'myObject'. The resulting expression is assigned to the propertyAccess variable.

Other functions in typescript

Sorted by popularity

function icon

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