CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ts-api-utils

Utility functions for working with TypeScript's API, providing comprehensive tools for analyzing and manipulating TypeScript AST nodes, types, and compiler APIs.

79

1.97x
Overview
Eval results
Files

task.mdevals/scenario-6/

Type Inspector

A TypeScript static analysis utility that inspects types for specific properties and callable signatures.

Capabilities

Inspects callable signatures

  • Given a function type, the inspector extracts all call signatures and returns their parameter and return type information @test
  • Given a union type containing callable types, the inspector collects call signatures from all union members @test
  • Given an intersection type containing callable types, the inspector collects call signatures from all intersection members @test

Inspects type properties

  • Given a type with regular properties, the inspector retrieves a specific property by name @test
  • Given a type with well-known symbol properties (like Symbol.iterator), the inspector retrieves the symbol property @test

Implementation

@generates

API

import * as ts from 'typescript';

/**
 * Extracts information about all call signatures from a type.
 * Returns an array of objects describing each signature's parameters and return type.
 *
 * @param type - The TypeScript type to inspect
 * @param typeChecker - The TypeScript type checker instance
 * @returns Array of signature information objects
 */
export function inspectCallSignatures(
  type: ts.Type,
  typeChecker: ts.TypeChecker
): Array<{ parameters: string[]; returnType: string }>;

/**
 * Retrieves a specific property from a type by name.
 * Returns the property symbol if found, undefined otherwise.
 *
 * @param type - The TypeScript type to inspect
 * @param propertyName - The name of the property to retrieve
 * @returns The property symbol or undefined
 */
export function getTypeProperty(
  type: ts.Type,
  propertyName: string
): ts.Symbol | undefined;

/**
 * Retrieves a well-known symbol property from a type.
 * Returns the symbol property if found, undefined otherwise.
 *
 * @param type - The TypeScript type to inspect
 * @param symbolName - The well-known symbol name (e.g., 'iterator', 'toStringTag')
 * @param typeChecker - The TypeScript type checker instance
 * @returns The symbol property or undefined
 */
export function getWellKnownSymbol(
  type: ts.Type,
  symbolName: string,
  typeChecker: ts.TypeChecker
): ts.Symbol | undefined;

Dependencies { .dependencies }

typescript { .dependency }

The TypeScript compiler API for type inspection.

ts-api-utils { .dependency }

Provides utility functions for working with TypeScript's API.

Install with Tessl CLI

npx tessl i tessl/npm-ts-api-utils

tile.json