tessl install tessl/npm-ts-api-utils@2.0.0Utility functions for working with TypeScript's API, providing comprehensive tools for analyzing and manipulating TypeScript AST nodes, types, and compiler APIs.
Agent Success
Agent success rate when using this tile
79%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.98x
Baseline
Agent success rate without this tile
40%
Build a TypeScript type analysis utility that categorizes and reports on TypeScript types within a given AST node. The analyzer should identify different type categories and provide statistics about type complexity.
Create a TypeScript module that exports a function analyzeTypes which takes a TypeScript AST node and a type checker, then returns an analysis report.
The analyzer must classify types into the following categories:
A | B)A & B)string, number, boolean, etc.For each type encountered, the analyzer should:
@generates
export interface TypeAnalysis {
unionTypes: number;
intersectionTypes: number;
literalTypes: {
string: number;
number: number;
boolean: number;
bigint: number;
};
objectTypes: number;
intrinsicTypes: number;
totalTypes: number;
}
export function analyzeTypes(
node: ts.Node,
typeChecker: ts.TypeChecker
): TypeAnalysis;string | number, the analyzer reports 1 union type with 2 intrinsic types @test{ name: string } & { age: number }, the analyzer reports 1 intersection type with 2 object types @test"hello" | "world" | 42, the analyzer reports 1 union type with 2 string literals and 1 number literal @test[string, number], the analyzer reports 1 object type (tuple) @testProvides TypeScript type analysis utilities.
Provides the TypeScript compiler API.