or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

ast-traversal.mdcode-analysis.mdcontrol-flow.mdindex.mdnode-typeguards.mdtext-processing.mdtype-guards.mdtype-utilities.mdvariable-usage.md

node-typeguards.mddocs/

0

# Node Type Guards

1

2

Type guard functions for TypeScript AST nodes using `ts.SyntaxKind` enumeration. These functions provide type-safe narrowing of `ts.Node` union types to specific node types, enabling safe access to type-specific properties and methods.

3

4

## Capabilities

5

6

### Basic Node Types

7

8

Core node type checking for fundamental AST constructs.

9

10

```typescript { .api }

11

/**

12

* Check if node is an identifier

13

* @param node - AST node to check

14

* @returns true if node is ts.Identifier

15

*/

16

function isIdentifier(node: ts.Node): node is ts.Identifier;

17

18

/**

19

* Check if node is a source file

20

* @param node - AST node to check

21

* @returns true if node is ts.SourceFile

22

*/

23

function isSourceFile(node: ts.Node): node is ts.SourceFile;

24

25

/**

26

* Check if node is a block statement

27

* @param node - AST node to check

28

* @returns true if node is ts.Block

29

*/

30

function isBlock(node: ts.Node): node is ts.Block;

31

32

/**

33

* Check if node is an expression

34

* @param node - AST node to check

35

* @returns true if node is ts.Expression

36

*/

37

function isExpression(node: ts.Node): node is ts.Expression;

38

```

39

40

### Literal Types

41

42

Type guards for all literal value types in TypeScript.

43

44

```typescript { .api }

45

/**

46

* Check if node is a string literal

47

* @param node - AST node to check

48

* @returns true if node is ts.StringLiteral

49

*/

50

function isStringLiteral(node: ts.Node): node is ts.StringLiteral;

51

52

/**

53

* Check if node is a numeric literal

54

* @param node - AST node to check

55

* @returns true if node is ts.NumericLiteral

56

*/

57

function isNumericLiteral(node: ts.Node): node is ts.NumericLiteral;

58

59

/**

60

* Check if node is a boolean literal (true/false)

61

* @param node - AST node to check

62

* @returns true if node is ts.BooleanLiteral

63

*/

64

function isBooleanLiteral(node: ts.Node): node is ts.BooleanLiteral;

65

66

/**

67

* Check if node is a null literal

68

* @param node - AST node to check

69

* @returns true if node is ts.NullLiteral

70

*/

71

function isNullLiteral(node: ts.Node): node is ts.NullLiteral;

72

73

/**

74

* Check if node is a BigInt literal (TypeScript 3.2+)

75

* @param node - AST node to check

76

* @returns true if node is ts.BigIntLiteral

77

*/

78

function isBigIntLiteral(node: ts.Node): node is ts.BigIntLiteral;

79

80

/**

81

* Check if node is a regular expression literal

82

* @param node - AST node to check

83

* @returns true if node is ts.RegularExpressionLiteral

84

*/

85

function isRegularExpressionLiteral(node: ts.Node): node is ts.RegularExpressionLiteral;

86

87

/**

88

* Check if node is a template expression with substitutions

89

* @param node - AST node to check

90

* @returns true if node is ts.TemplateExpression

91

*/

92

function isTemplateExpression(node: ts.Node): node is ts.TemplateExpression;

93

94

/**

95

* Check if node is a template literal without substitutions

96

* @param node - AST node to check

97

* @returns true if node is ts.NoSubstitutionTemplateLiteral

98

*/

99

function isNoSubstitutionTemplateLiteral(node: ts.Node): node is ts.NoSubstitutionTemplateLiteral;

100

```

101

102

### Declaration Types

103

104

Type guards for all declaration constructs in TypeScript.

105

106

```typescript { .api }

107

/**

108

* Check if node is a variable declaration

109

* @param node - AST node to check

110

* @returns true if node is ts.VariableDeclaration

111

*/

112

function isVariableDeclaration(node: ts.Node): node is ts.VariableDeclaration;

113

114

/**

115

* Check if node is a variable statement

116

* @param node - AST node to check

117

* @returns true if node is ts.VariableStatement

118

*/

119

function isVariableStatement(node: ts.Node): node is ts.VariableStatement;

120

121

/**

122

* Check if node is a function declaration

123

* @param node - AST node to check

124

* @returns true if node is ts.FunctionDeclaration

125

*/

126

function isFunctionDeclaration(node: ts.Node): node is ts.FunctionDeclaration;

127

128

/**

129

* Check if node is a class declaration

130

* @param node - AST node to check

131

* @returns true if node is ts.ClassDeclaration

132

*/

133

function isClassDeclaration(node: ts.Node): node is ts.ClassDeclaration;

134

135

/**

136

* Check if node is an interface declaration

137

* @param node - AST node to check

138

* @returns true if node is ts.InterfaceDeclaration

139

*/

140

function isInterfaceDeclaration(node: ts.Node): node is ts.InterfaceDeclaration;

141

142

/**

143

* Check if node is a type alias declaration

144

* @param node - AST node to check

145

* @returns true if node is ts.TypeAliasDeclaration

146

*/

147

function isTypeAliasDeclaration(node: ts.Node): node is ts.TypeAliasDeclaration;

148

149

/**

150

* Check if node is an enum declaration

151

* @param node - AST node to check

152

* @returns true if node is ts.EnumDeclaration

153

*/

154

function isEnumDeclaration(node: ts.Node): node is ts.EnumDeclaration;

155

156

/**

157

* Check if node is a module declaration

158

* @param node - AST node to check

159

* @returns true if node is ts.ModuleDeclaration

160

*/

161

function isModuleDeclaration(node: ts.Node): node is ts.ModuleDeclaration;

162

163

/**

164

* Check if node is an enum member

165

* @param node - AST node to check

166

* @returns true if node is ts.EnumMember

167

*/

168

function isEnumMember(node: ts.Node): node is ts.EnumMember;

169

```

170

171

### Function-like Constructs

172

173

Type guards for function-like declarations and expressions.

174

175

```typescript { .api }

176

/**

177

* Check if node is a function expression

178

* @param node - AST node to check

179

* @returns true if node is ts.FunctionExpression

180

*/

181

function isFunctionExpression(node: ts.Node): node is ts.FunctionExpression;

182

183

/**

184

* Check if node is an arrow function

185

* @param node - AST node to check

186

* @returns true if node is ts.ArrowFunction

187

*/

188

function isArrowFunction(node: ts.Node): node is ts.ArrowFunction;

189

190

/**

191

* Check if node is a method declaration

192

* @param node - AST node to check

193

* @returns true if node is ts.MethodDeclaration

194

*/

195

function isMethodDeclaration(node: ts.Node): node is ts.MethodDeclaration;

196

197

/**

198

* Check if node is a constructor declaration

199

* @param node - AST node to check

200

* @returns true if node is ts.ConstructorDeclaration

201

*/

202

function isConstructorDeclaration(node: ts.Node): node is ts.ConstructorDeclaration;

203

204

/**

205

* Check if node is a getter accessor declaration

206

* @param node - AST node to check

207

* @returns true if node is ts.GetAccessorDeclaration

208

*/

209

function isGetAccessorDeclaration(node: ts.Node): node is ts.GetAccessorDeclaration;

210

211

/**

212

* Check if node is a setter accessor declaration

213

* @param node - AST node to check

214

* @returns true if node is ts.SetAccessorDeclaration

215

*/

216

function isSetAccessorDeclaration(node: ts.Node): node is ts.SetAccessorDeclaration;

217

```

218

219

### Property Access and Assignment

220

221

Type guards for property access patterns and object property assignments.

222

223

```typescript { .api }

224

/**

225

* Check if node is a property access expression (obj.prop)

226

* @param node - AST node to check

227

* @returns true if node is ts.PropertyAccessExpression

228

*/

229

function isPropertyAccessExpression(node: ts.Node): node is ts.PropertyAccessExpression;

230

231

/**

232

* Check if node is an element access expression (obj[key])

233

* @param node - AST node to check

234

* @returns true if node is ts.ElementAccessExpression

235

*/

236

function isElementAccessExpression(node: ts.Node): node is ts.ElementAccessExpression;

237

238

/**

239

* Check if node is a property declaration

240

* @param node - AST node to check

241

* @returns true if node is ts.PropertyDeclaration

242

*/

243

function isPropertyDeclaration(node: ts.Node): node is ts.PropertyDeclaration;

244

245

/**

246

* Check if node is a property assignment in object literal

247

* @param node - AST node to check

248

* @returns true if node is ts.PropertyAssignment

249

*/

250

function isPropertyAssignment(node: ts.Node): node is ts.PropertyAssignment;

251

252

/**

253

* Check if node is a shorthand property assignment ({prop})

254

* @param node - AST node to check

255

* @returns true if node is ts.ShorthandPropertyAssignment

256

*/

257

function isShorthandPropertyAssignment(node: ts.Node): node is ts.ShorthandPropertyAssignment;

258

259

/**

260

* Check if node is a spread assignment in object literal ({...obj})

261

* @param node - AST node to check

262

* @returns true if node is ts.SpreadAssignment

263

*/

264

function isSpreadAssignment(node: ts.Node): node is ts.SpreadAssignment;

265

```

266

267

### Call and New Expressions

268

269

Type guards for function calls and object instantiation.

270

271

```typescript { .api }

272

/**

273

* Check if node is a call expression

274

* @param node - AST node to check

275

* @returns true if node is ts.CallExpression

276

*/

277

function isCallExpression(node: ts.Node): node is ts.CallExpression;

278

279

/**

280

* Check if node is a new expression

281

* @param node - AST node to check

282

* @returns true if node is ts.NewExpression

283

*/

284

function isNewExpression(node: ts.Node): node is ts.NewExpression;

285

286

/**

287

* Check if node is a tagged template expression

288

* @param node - AST node to check

289

* @returns true if node is ts.TaggedTemplateExpression

290

*/

291

function isTaggedTemplateExpression(node: ts.Node): node is ts.TaggedTemplateExpression;

292

```

293

294

### Control Flow Statements

295

296

Type guards for control flow constructs including conditionals, loops, and flow control.

297

298

```typescript { .api }

299

/**

300

* Check if node is an if statement

301

* @param node - AST node to check

302

* @returns true if node is ts.IfStatement

303

*/

304

function isIfStatement(node: ts.Node): node is ts.IfStatement;

305

306

/**

307

* Check if node is a for statement

308

* @param node - AST node to check

309

* @returns true if node is ts.ForStatement

310

*/

311

function isForStatement(node: ts.Node): node is ts.ForStatement;

312

313

/**

314

* Check if node is a for-in statement

315

* @param node - AST node to check

316

* @returns true if node is ts.ForInStatement

317

*/

318

function isForInStatement(node: ts.Node): node is ts.ForInStatement;

319

320

/**

321

* Check if node is a for-of statement

322

* @param node - AST node to check

323

* @returns true if node is ts.ForOfStatement

324

*/

325

function isForOfStatement(node: ts.Node): node is ts.ForOfStatement;

326

327

/**

328

* Check if node is a while statement

329

* @param node - AST node to check

330

* @returns true if node is ts.WhileStatement

331

*/

332

function isWhileStatement(node: ts.Node): node is ts.WhileStatement;

333

334

/**

335

* Check if node is a do-while statement

336

* @param node - AST node to check

337

* @returns true if node is ts.DoStatement

338

*/

339

function isDoStatement(node: ts.Node): node is ts.DoStatement;

340

341

/**

342

* Check if node is a switch statement

343

* @param node - AST node to check

344

* @returns true if node is ts.SwitchStatement

345

*/

346

function isSwitchStatement(node: ts.Node): node is ts.SwitchStatement;

347

348

/**

349

* Check if node is a case clause

350

* @param node - AST node to check

351

* @returns true if node is ts.CaseClause

352

*/

353

function isCaseClause(node: ts.Node): node is ts.CaseClause;

354

355

/**

356

* Check if node is a default clause

357

* @param node - AST node to check

358

* @returns true if node is ts.DefaultClause

359

*/

360

function isDefaultClause(node: ts.Node): node is ts.DefaultClause;

361

362

/**

363

* Check if node is a break statement

364

* @param node - AST node to check

365

* @returns true if node is ts.BreakStatement

366

*/

367

function isBreakStatement(node: ts.Node): node is ts.BreakStatement;

368

369

/**

370

* Check if node is a continue statement

371

* @param node - AST node to check

372

* @returns true if node is ts.ContinueStatement

373

*/

374

function isContinueStatement(node: ts.Node): node is ts.ContinueStatement;

375

376

/**

377

* Check if node is a return statement

378

* @param node - AST node to check

379

* @returns true if node is ts.ReturnStatement

380

*/

381

function isReturnStatement(node: ts.Node): node is ts.ReturnStatement;

382

383

/**

384

* Check if node is a throw statement

385

* @param node - AST node to check

386

* @returns true if node is ts.ThrowStatement

387

*/

388

function isThrowStatement(node: ts.Node): node is ts.ThrowStatement;

389

390

/**

391

* Check if node is a try statement

392

* @param node - AST node to check

393

* @returns true if node is ts.TryStatement

394

*/

395

function isTryStatement(node: ts.Node): node is ts.TryStatement;

396

```

397

398

### Type Nodes

399

400

Type guards for TypeScript type annotation nodes.

401

402

```typescript { .api }

403

/**

404

* Check if node is a type reference node

405

* @param node - AST node to check

406

* @returns true if node is ts.TypeReferenceNode

407

*/

408

function isTypeReferenceNode(node: ts.Node): node is ts.TypeReferenceNode;

409

410

/**

411

* Check if node is a type literal node

412

* @param node - AST node to check

413

* @returns true if node is ts.TypeLiteralNode

414

*/

415

function isTypeLiteralNode(node: ts.Node): node is ts.TypeLiteralNode;

416

417

/**

418

* Check if node is a union type node

419

* @param node - AST node to check

420

* @returns true if node is ts.UnionTypeNode

421

*/

422

function isUnionTypeNode(node: ts.Node): node is ts.UnionTypeNode;

423

424

/**

425

* Check if node is an intersection type node

426

* @param node - AST node to check

427

* @returns true if node is ts.IntersectionTypeNode

428

*/

429

function isIntersectionTypeNode(node: ts.Node): node is ts.IntersectionTypeNode;

430

431

/**

432

* Check if node is a tuple type node

433

* @param node - AST node to check

434

* @returns true if node is ts.TupleTypeNode

435

*/

436

function isTupleTypeNode(node: ts.Node): node is ts.TupleTypeNode;

437

438

/**

439

* Check if node is an array type node

440

* @param node - AST node to check

441

* @returns true if node is ts.ArrayTypeNode

442

*/

443

function isArrayTypeNode(node: ts.Node): node is ts.ArrayTypeNode;

444

445

/**

446

* Check if node is a function type node

447

* @param node - AST node to check

448

* @returns true if node is ts.FunctionTypeNode

449

*/

450

function isFunctionTypeNode(node: ts.Node): node is ts.FunctionTypeNode;

451

452

/**

453

* Check if node is a constructor type node

454

* @param node - AST node to check

455

* @returns true if node is ts.ConstructorTypeNode

456

*/

457

function isConstructorTypeNode(node: ts.Node): node is ts.ConstructorTypeNode;

458

459

/**

460

* Check if node is a conditional type node

461

* @param node - AST node to check

462

* @returns true if node is ts.ConditionalTypeNode

463

*/

464

function isConditionalTypeNode(node: ts.Node): node is ts.ConditionalTypeNode;

465

466

/**

467

* Check if node is an infer type node

468

* @param node - AST node to check

469

* @returns true if node is ts.InferTypeNode

470

*/

471

function isInferTypeNode(node: ts.Node): node is ts.InferTypeNode;

472

473

/**

474

* Check if node is a mapped type node

475

* @param node - AST node to check

476

* @returns true if node is ts.MappedTypeNode

477

*/

478

function isMappedTypeNode(node: ts.Node): node is ts.MappedTypeNode;

479

480

/**

481

* Check if node is a literal type node

482

* @param node - AST node to check

483

* @returns true if node is ts.LiteralTypeNode

484

*/

485

function isLiteralTypeNode(node: ts.Node): node is ts.LiteralTypeNode;

486

487

/**

488

* Check if node is an indexed access type node

489

* @param node - AST node to check

490

* @returns true if node is ts.IndexedAccessTypeNode

491

*/

492

function isIndexedAccessTypeNode(node: ts.Node): node is ts.IndexedAccessTypeNode;

493

494

/**

495

* Check if node is a type operator node (keyof, typeof, etc.)

496

* @param node - AST node to check

497

* @returns true if node is ts.TypeOperatorNode

498

*/

499

function isTypeOperatorNode(node: ts.Node): node is ts.TypeOperatorNode;

500

501

/**

502

* Check if node is a type query node (typeof expression)

503

* @param node - AST node to check

504

* @returns true if node is ts.TypeQueryNode

505

*/

506

function isTypeQueryNode(node: ts.Node): node is ts.TypeQueryNode;

507

508

/**

509

* Check if node is an optional type node (TypeScript 3.0+)

510

* @param node - AST node to check

511

* @returns true if node is ts.OptionalTypeNode

512

*/

513

function isOptionalTypeNode(node: ts.Node): node is ts.OptionalTypeNode;

514

515

/**

516

* Check if node is a rest type node (TypeScript 3.0+)

517

* @param node - AST node to check

518

* @returns true if node is ts.RestTypeNode

519

*/

520

function isRestTypeNode(node: ts.Node): node is ts.RestTypeNode;

521

```

522

523

### Import and Export Statements

524

525

Type guards for module import and export constructs.

526

527

```typescript { .api }

528

/**

529

* Check if node is an import declaration

530

* @param node - AST node to check

531

* @returns true if node is ts.ImportDeclaration

532

*/

533

function isImportDeclaration(node: ts.Node): node is ts.ImportDeclaration;

534

535

/**

536

* Check if node is an import clause

537

* @param node - AST node to check

538

* @returns true if node is ts.ImportClause

539

*/

540

function isImportClause(node: ts.Node): node is ts.ImportClause;

541

542

/**

543

* Check if node is a namespace import (* as name)

544

* @param node - AST node to check

545

* @returns true if node is ts.NamespaceImport

546

*/

547

function isNamespaceImport(node: ts.Node): node is ts.NamespaceImport;

548

549

/**

550

* Check if node is named imports ({name1, name2})

551

* @param node - AST node to check

552

* @returns true if node is ts.NamedImports

553

*/

554

function isNamedImports(node: ts.Node): node is ts.NamedImports;

555

556

/**

557

* Check if node is an import specifier

558

* @param node - AST node to check

559

* @returns true if node is ts.ImportSpecifier

560

*/

561

function isImportSpecifier(node: ts.Node): node is ts.ImportSpecifier;

562

563

/**

564

* Check if node is an import equals declaration

565

* @param node - AST node to check

566

* @returns true if node is ts.ImportEqualsDeclaration

567

*/

568

function isImportEqualsDeclaration(node: ts.Node): node is ts.ImportEqualsDeclaration;

569

570

/**

571

* Check if node is an export declaration

572

* @param node - AST node to check

573

* @returns true if node is ts.ExportDeclaration

574

*/

575

function isExportDeclaration(node: ts.Node): node is ts.ExportDeclaration;

576

577

/**

578

* Check if node is an export assignment

579

* @param node - AST node to check

580

* @returns true if node is ts.ExportAssignment

581

*/

582

function isExportAssignment(node: ts.Node): node is ts.ExportAssignment;

583

584

/**

585

* Check if node is an export specifier

586

* @param node - AST node to check

587

* @returns true if node is ts.ExportSpecifier

588

*/

589

function isExportSpecifier(node: ts.Node): node is ts.ExportSpecifier;

590

591

/**

592

* Check if node is named exports ({name1, name2})

593

* @param node - AST node to check

594

* @returns true if node is ts.NamedExports

595

*/

596

function isNamedExports(node: ts.Node): node is ts.NamedExports;

597

598

/**

599

* Check if node is an import type node (TypeScript 2.9+)

600

* @param node - AST node to check

601

* @returns true if node is ts.ImportTypeNode

602

*/

603

function isImportTypeNode(node: ts.Node): node is ts.ImportTypeNode;

604

```

605

606

### JSX Elements

607

608

Type guards for JSX syntax elements.

609

610

```typescript { .api }

611

/**

612

* Check if node is a JSX element

613

* @param node - AST node to check

614

* @returns true if node is ts.JsxElement

615

*/

616

function isJsxElement(node: ts.Node): node is ts.JsxElement;

617

618

/**

619

* Check if node is a JSX self-closing element

620

* @param node - AST node to check

621

* @returns true if node is ts.JsxSelfClosingElement

622

*/

623

function isJsxSelfClosingElement(node: ts.Node): node is ts.JsxSelfClosingElement;

624

625

/**

626

* Check if node is a JSX opening element

627

* @param node - AST node to check

628

* @returns true if node is ts.JsxOpeningElement

629

*/

630

function isJsxOpeningElement(node: ts.Node): node is ts.JsxOpeningElement;

631

632

/**

633

* Check if node is a JSX closing element

634

* @param node - AST node to check

635

* @returns true if node is ts.JsxClosingElement

636

*/

637

function isJsxClosingElement(node: ts.Node): node is ts.JsxClosingElement;

638

639

/**

640

* Check if node is a JSX fragment

641

* @param node - AST node to check

642

* @returns true if node is ts.JsxFragment

643

*/

644

function isJsxFragment(node: ts.Node): node is ts.JsxFragment;

645

646

/**

647

* Check if node is a JSX opening fragment

648

* @param node - AST node to check

649

* @returns true if node is ts.JsxOpeningFragment

650

*/

651

function isJsxOpeningFragment(node: ts.Node): node is ts.JsxOpeningFragment;

652

653

/**

654

* Check if node is a JSX closing fragment

655

* @param node - AST node to check

656

* @returns true if node is ts.JsxClosingFragment

657

*/

658

function isJsxClosingFragment(node: ts.Node): node is ts.JsxClosingFragment;

659

660

/**

661

* Check if node is a JSX attribute

662

* @param node - AST node to check

663

* @returns true if node is ts.JsxAttribute

664

*/

665

function isJsxAttribute(node: ts.Node): node is ts.JsxAttribute;

666

667

/**

668

* Check if node is JSX attributes

669

* @param node - AST node to check

670

* @returns true if node is ts.JsxAttributes

671

*/

672

function isJsxAttributes(node: ts.Node): node is ts.JsxAttributes;

673

674

/**

675

* Check if node is a JSX spread attribute

676

* @param node - AST node to check

677

* @returns true if node is ts.JsxSpreadAttribute

678

*/

679

function isJsxSpreadAttribute(node: ts.Node): node is ts.JsxSpreadAttribute;

680

681

/**

682

* Check if node is a JSX expression

683

* @param node - AST node to check

684

* @returns true if node is ts.JsxExpression

685

*/

686

function isJsxExpression(node: ts.Node): node is ts.JsxExpression;

687

688

/**

689

* Check if node is JSX text

690

* @param node - AST node to check

691

* @returns true if node is ts.JsxText

692

*/

693

function isJsxText(node: ts.Node): node is ts.JsxText;

694

```

695

696

### Composite and Utility Checks

697

698

Composite type guards that check for multiple related node types.

699

700

```typescript { .api }

701

/**

702

* Check if node is block-like (can contain statements)

703

* @param node - AST node to check

704

* @returns true if node is ts.BlockLike

705

*/

706

function isBlockLike(node: ts.Node): node is ts.BlockLike;

707

708

/**

709

* Check if node is an entity name (identifier or qualified name)

710

* @param node - AST node to check

711

* @returns true if node is ts.EntityName

712

*/

713

function isEntityName(node: ts.Node): node is ts.EntityName;

714

715

/**

716

* Check if node is an entity name expression

717

* @param node - AST node to check

718

* @returns true if node is ts.EntityNameExpression

719

*/

720

function isEntityNameExpression(node: ts.Node): node is ts.EntityNameExpression;

721

722

/**

723

* Check if node is a type assertion expression

724

* @param node - AST node to check

725

* @returns true if node is ts.AssertionExpression

726

*/

727

function isAssertionExpression(node: ts.Node): node is ts.AssertionExpression;

728

729

/**

730

* Check if node is a call-like expression

731

* @param node - AST node to check

732

* @returns true if node is ts.CallLikeExpression

733

*/

734

function isCallLikeExpression(node: ts.Node): node is ts.CallLikeExpression;

735

736

/**

737

* Check if node is an iteration statement (for/while/do)

738

* @param node - AST node to check

739

* @returns true if node is ts.IterationStatement

740

*/

741

function isIterationStatement(node: ts.Node): node is ts.IterationStatement;

742

743

/**

744

* Check if node is numeric or string-like literal

745

* @param node - AST node to check

746

* @returns true if node is numeric, string, or template literal

747

*/

748

function isNumericOrStringLikeLiteral(node: ts.Node): node is ts.NumericLiteral | ts.StringLiteral | ts.NoSubstitutionTemplateLiteral;

749

750

/**

751

* Check if node is textual literal (string or template)

752

* @param node - AST node to check

753

* @returns true if node is ts.StringLiteral or ts.NoSubstitutionTemplateLiteral

754

*/

755

function isTextualLiteral(node: ts.Node): node is ts.StringLiteral | ts.NoSubstitutionTemplateLiteral;

756

```

757

758

**Usage Example:**

759

760

```typescript

761

import * as ts from "typescript";

762

import { isIdentifier, isCallExpression, isStringLiteral } from "tsutils/typeguard";

763

764

function analyzeNode(node: ts.Node) {

765

if (isIdentifier(node)) {

766

// node is now typed as ts.Identifier

767

console.log("Identifier name:", node.text);

768

console.log("Original keyword kind:", node.originalKeywordKind);

769

}

770

771

if (isCallExpression(node)) {

772

// node is now typed as ts.CallExpression

773

console.log("Function expression:", node.expression);

774

console.log("Argument count:", node.arguments.length);

775

}

776

777

if (isStringLiteral(node)) {

778

// node is now typed as ts.StringLiteral

779

console.log("String value:", node.text);

780

}

781

}

782

```