kungfooman / RuntimeTypeInspector.js

Checking JSDoc types at runtime for high-quality types - Trust is good, control is better.
MIT License
8 stars 0 forks source link

Structurize AST from ConditionalType in both TS/Babel-TS #34

Closed kungfooman closed 10 months ago

kungfooman commented 10 months ago

Example:

/**
 * This creates a nested array of a given type and depth (see examples).
 * 
 * @example
 *   NestArray<string, 1>; // string[]
 * @example
 *   NestArray<number, 2>; // number[][]
 * @example
 *   NestArray<string, 3>; // string[][][] etc.
 * @template T
 * @template {number} Depth
 * @template {never[]} [Acc=[]]
 * @typedef {Acc['length'] extends Depth ? T : NestArray<T[], Depth, [...Acc, never]>} NestArray
 */

Current output is simply:

expandType.mjs:206 toSourceTS> unhandled kind - make sure to understand you cannot reverse TS enums

Putting them into structure is one thing, but type-checking them at runtime is an entirely different matter for later.

In order to parse the entire example, I also have to implement:

Acc['length'] - a TSIndexedAccessType NestArray<...> - a "non-stock" reference type, unlike Promise, Map, Array etc. [...Acc, never] - a RestType