Utility functions for working with TypeScript's API, providing comprehensive tools for analyzing and manipulating TypeScript AST nodes, types, and compiler APIs.
79
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.
Install with Tessl CLI
npx tessl i tessl/npm-ts-api-utilsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10