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 type analysis tool that analyzes TypeScript types and generates detailed reports about their characteristics.
The tool should analyze TypeScript types and detect the following properties:
When given union or intersection types, the tool should be able to extract and report their constituent types. For unions, list all the types that are combined with |. For intersections, list all the types that are combined with &.
Identify types that are definitively falsy (e.g., false, null, undefined, 0, empty string literal types).
For object types with properties, determine whether specific properties are readonly. The analysis should handle both explicit readonly modifiers and readonly mapped types.
Detect whether a type represents a thenable/awaitable value (e.g., Promise-like types with a then method).
Identify whether a type is a literal type (string literal, number literal, boolean literal, etc.).
Your implementation should provide a function that takes a TypeScript type and returns an analysis report containing:
@generates
import * as ts from 'typescript';
export interface TypeAnalysisReport {
constituents?: {
unions?: ts.Type[];
intersections?: ts.Type[];
};
isFalsy: boolean;
isThenable: boolean;
isLiteral: boolean;
readonlyProperties?: string[];
}
export function analyzeType(
type: ts.Type,
typeChecker: ts.TypeChecker,
node?: ts.Node
): TypeAnalysisReport;string | number | boolean, the constituents should list all three types @test{ a: string } & { b: number }, the constituents should list both object types @testfalse should be identified as falsy @testnull should be identified as falsy @test"hello" (string literal) should be identified as a literal type @test42 (number literal) should be identified as a literal type @testProvides TypeScript compiler API for type checking and analysis.
Provides utility functions for working with TypeScript's API, including type analysis capabilities.