tsutils (3.21.0)

Published 2026-02-24 14:06:26 +00:00 by atheaadmin

Installation

registry=
npm install tsutils@3.21.0
"tsutils": "3.21.0"

About this package

Utility functions for working with typescript's AST

Greenkeeper badge

Usage

This package consists of two major parts: utilities and typeguard functions. By importing the project you will get both of them.

import * as utils from "tsutils";
utils.isIdentifier(node); // typeguard
utils.getLineRanges(sourceFile); // utilities

If you don't need everything offered by this package, you can select what should be imported. The parts that are not imported are never read from disk and may save some startup time and reduce memory consumtion.

If you only need typeguards you can explicitly import them:

import { isIdentifier } from "tsutils/typeguard";
// You can even distiguish between typeguards for nodes and types
import { isUnionTypeNode } from "tsutils/typeguard/node";
import { isUnionType } from "tsutils/typeguard/type";

If you only need the utilities you can also explicitly import them:

import { forEachComment, forEachToken } from "tsutils/util";

Typescript version dependency

This package is backwards compatible with typescript 2.8.0 at runtime although compiling might need a newer version of typescript installed.

Using typescript@next might work, but it's not officially supported. If you encounter any bugs, please open an issue.

For compatibility with older versions of TypeScript typeguard functions are separated by TypeScript version. If you are stuck on typescript@2.8, you should import directly from the submodule for that version:

// all typeguards compatible with typescript@2.8
import { isIdentifier } from "tsutils/typeguard/2.8";
// you can even use nested submodules
import { isIdentifier } from "tsutils/typeguard/2.8/node";

// all typeguards compatible with typescript@2.9 (includes those of 2.8)
import { isIdentifier } from "tsutils/typeguard/2.9";

// always points to the latest stable version (2.9 as of writing this)
import { isIdentifier } from "tsutils/typeguard";
import { isIdentifier } from "tsutils";

// always points to the typeguards for the next TypeScript version (3.0 as of writing this)
import { isIdentifier } from "tsutils/typeguard/next";

Note that if you are also using utility functions, you should prefer the relevant submodule:

// importing directly from 'tsutils' would pull in the latest typeguards
import { forEachToken } from 'tsutils/util';
import { isIdentifier } from 'tsutils/typeguard/2.8';

Dependencies

Dependencies

ID Version
tslib ^1.8.1

Development Dependencies

ID Version
@fimbul/mithotyn ^0.21.0
@fimbul/valtyr ^0.22.0
@fimbul/wotan ^0.22.0
@types/chai ^4.0.10
@types/mocha ^5.0.0
@types/node ^11.13.0
chai ^4.1.2
coveralls ^3.0.0
github-release-from-changelog ^1.3.0
mocha ^6.0.2
npm-run-all ^4.1.2
nyc ^13.3.0
rimraf ^3.0.2
ts-transform-const-enum ^0.0.1
tslint ^5.8.0
tslint-consistent-codestyle ^1.11.0
ttypescript ^1.5.5
typescript 4.2.0-dev.20201230

Peer Dependencies

ID Version
typescript >=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta

Keywords

typescript ts ast typeguard utils helper node
Details
npm
2026-02-24 14:06:26 +00:00
0
Klaus Meinhardt
MIT
latest
70 KiB
Assets (1)
Versions (1) View all
3.21.0 2026-02-24