mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-22 00:11:02 -05:00
Made an interface that represents type definition
This commit is contained in:
parent
0c09b68595
commit
c0cacb57b1
1 changed files with 57 additions and 0 deletions
57
src/utils/typescript/typescript-type-definition.ts
Normal file
57
src/utils/typescript/typescript-type-definition.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { TypeScriptNode } from "./typescript-node";
|
||||
|
||||
/**
|
||||
* Represents a TypeScript type definition.
|
||||
*/
|
||||
export interface TypeScriptTypeDefinition extends TypeScriptNode {
|
||||
/**
|
||||
* Indicates whether this type definition represents a composite type.
|
||||
*
|
||||
* @returns `true` if the type definition is a composite type; otherwise, `false`.
|
||||
*/
|
||||
get isComposite(): boolean;
|
||||
|
||||
/**
|
||||
* Indicates whether this type definition represents a union type.
|
||||
*
|
||||
* @returns `true` if the type definition is a union type; otherwise, `false`.
|
||||
*/
|
||||
get isUnion(): boolean;
|
||||
|
||||
/**
|
||||
* Indicates whether this type definition represents an intersection type.
|
||||
*
|
||||
* @returns `true` if the type definition is an intersection type; otherwise, `false`.
|
||||
*/
|
||||
get isIntersection(): boolean;
|
||||
|
||||
/**
|
||||
* Gets a value indicating whether this type definition represents an alias.
|
||||
*
|
||||
* @returns `true` if this type definition represents an alias; otherwise, `false`.
|
||||
*/
|
||||
get isAlias(): boolean;
|
||||
|
||||
/**
|
||||
* Returns an iterable of TypeScriptTypeDefinition objects representing the composing types of this type definition.
|
||||
*/
|
||||
composingTypes(): Iterable<TypeScriptTypeDefinition>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Yields all the composing types of a given TypeScript type.
|
||||
*
|
||||
* @param type - The input TypeScriptTypeDefinition to decompose.
|
||||
*
|
||||
* @yields The next composing type of the input type.
|
||||
*/
|
||||
export function* decomposeType(type: TypeScriptTypeDefinition): Iterable<TypeScriptTypeDefinition> {
|
||||
if (!type.isComposite) {
|
||||
yield type;
|
||||
return;
|
||||
}
|
||||
|
||||
for (const composingType of type.composingTypes()) {
|
||||
yield* decomposeType(composingType);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue