@goast/typescript 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/src/assets.d.ts +18 -0
  2. package/dist/src/assets.js +18 -0
  3. package/dist/src/ast/common.d.ts +6 -0
  4. package/dist/src/ast/node.d.ts +15 -0
  5. package/dist/src/ast/node.js +15 -0
  6. package/dist/src/ast/nodes/argument.d.ts +31 -0
  7. package/dist/src/ast/nodes/argument.js +31 -0
  8. package/dist/src/ast/nodes/array-type.d.ts +32 -0
  9. package/dist/src/ast/nodes/array-type.js +32 -0
  10. package/dist/src/ast/nodes/arrow-function.d.ts +56 -0
  11. package/dist/src/ast/nodes/arrow-function.js +56 -0
  12. package/dist/src/ast/nodes/call.d.ts +34 -0
  13. package/dist/src/ast/nodes/call.js +34 -0
  14. package/dist/src/ast/nodes/class.d.ts +73 -0
  15. package/dist/src/ast/nodes/class.js +73 -0
  16. package/dist/src/ast/nodes/constructor-parameter.d.ts +37 -0
  17. package/dist/src/ast/nodes/constructor-parameter.js +37 -0
  18. package/dist/src/ast/nodes/constructor.d.ts +44 -0
  19. package/dist/src/ast/nodes/constructor.js +44 -0
  20. package/dist/src/ast/nodes/decorator.d.ts +35 -0
  21. package/dist/src/ast/nodes/decorator.js +35 -0
  22. package/dist/src/ast/nodes/doc-tag.d.ts +39 -0
  23. package/dist/src/ast/nodes/doc-tag.js +39 -0
  24. package/dist/src/ast/nodes/doc.d.ts +38 -0
  25. package/dist/src/ast/nodes/doc.js +38 -0
  26. package/dist/src/ast/nodes/enum-value.d.ts +37 -0
  27. package/dist/src/ast/nodes/enum-value.js +37 -0
  28. package/dist/src/ast/nodes/enum.d.ts +47 -0
  29. package/dist/src/ast/nodes/enum.js +47 -0
  30. package/dist/src/ast/nodes/export.d.ts +51 -0
  31. package/dist/src/ast/nodes/export.js +51 -0
  32. package/dist/src/ast/nodes/function-type.d.ts +35 -0
  33. package/dist/src/ast/nodes/function-type.js +35 -0
  34. package/dist/src/ast/nodes/function.d.ts +61 -0
  35. package/dist/src/ast/nodes/function.js +61 -0
  36. package/dist/src/ast/nodes/generic-parameter.d.ts +44 -0
  37. package/dist/src/ast/nodes/generic-parameter.js +44 -0
  38. package/dist/src/ast/nodes/indexer.d.ts +41 -0
  39. package/dist/src/ast/nodes/indexer.js +41 -0
  40. package/dist/src/ast/nodes/interface.d.ts +57 -0
  41. package/dist/src/ast/nodes/interface.js +57 -0
  42. package/dist/src/ast/nodes/intersection-type.d.ts +32 -0
  43. package/dist/src/ast/nodes/intersection-type.js +32 -0
  44. package/dist/src/ast/nodes/lookup-type.d.ts +34 -0
  45. package/dist/src/ast/nodes/lookup-type.js +34 -0
  46. package/dist/src/ast/nodes/method.d.ts +90 -0
  47. package/dist/src/ast/nodes/method.js +90 -0
  48. package/dist/src/ast/nodes/object-type.d.ts +34 -0
  49. package/dist/src/ast/nodes/object-type.js +34 -0
  50. package/dist/src/ast/nodes/object.d.ts +34 -0
  51. package/dist/src/ast/nodes/object.js +34 -0
  52. package/dist/src/ast/nodes/parameter.d.ts +51 -0
  53. package/dist/src/ast/nodes/parameter.js +51 -0
  54. package/dist/src/ast/nodes/property-accessor.d.ts +94 -0
  55. package/dist/src/ast/nodes/property-accessor.js +94 -0
  56. package/dist/src/ast/nodes/property.d.ts +113 -0
  57. package/dist/src/ast/nodes/property.js +113 -0
  58. package/dist/src/ast/nodes/reference.d.ts +90 -0
  59. package/dist/src/ast/nodes/reference.js +66 -0
  60. package/dist/src/ast/nodes/string.d.ts +35 -0
  61. package/dist/src/ast/nodes/string.js +35 -0
  62. package/dist/src/ast/nodes/tuple.d.ts +33 -0
  63. package/dist/src/ast/nodes/tuple.js +33 -0
  64. package/dist/src/ast/nodes/type-alias.d.ts +44 -0
  65. package/dist/src/ast/nodes/type-alias.js +44 -0
  66. package/dist/src/ast/nodes/typeof.d.ts +41 -0
  67. package/dist/src/ast/nodes/typeof.js +41 -0
  68. package/dist/src/ast/nodes/types.d.ts +12 -0
  69. package/dist/src/ast/nodes/union-type.d.ts +31 -0
  70. package/dist/src/ast/nodes/union-type.js +31 -0
  71. package/dist/src/ast/nodes/variable.d.ts +46 -0
  72. package/dist/src/ast/nodes/variable.js +46 -0
  73. package/dist/src/ast/references/angular.d.ts +7 -0
  74. package/dist/src/ast/references/angular.js +7 -0
  75. package/dist/src/ast/references/easy-network-stub.d.ts +4 -0
  76. package/dist/src/ast/references/easy-network-stub.js +4 -0
  77. package/dist/src/ast/references/k6.d.ts +3 -0
  78. package/dist/src/ast/references/k6.js +3 -0
  79. package/dist/src/ast/references/rxjs.d.ts +5 -0
  80. package/dist/src/ast/references/rxjs.js +5 -0
  81. package/dist/src/ast/references/typescript.d.ts +30 -0
  82. package/dist/src/ast/references/typescript.js +30 -0
  83. package/dist/src/ast/utils/get-type-script-builder-options.d.ts +8 -0
  84. package/dist/src/ast/utils/get-type-script-builder-options.js +8 -0
  85. package/dist/src/ast/utils/to-ts-node.d.ts +28 -0
  86. package/dist/src/ast/utils/write-ts-generic-parameters.d.ts +9 -0
  87. package/dist/src/ast/utils/write-ts-generic-parameters.js +9 -0
  88. package/dist/src/ast/utils/write-ts-members.d.ts +12 -0
  89. package/dist/src/ast/utils/write-ts-members.js +12 -0
  90. package/dist/src/ast/utils/write-ts-nodes.d.ts +16 -0
  91. package/dist/src/ast/utils/write-ts-nodes.js +16 -0
  92. package/dist/src/ast/utils/write-ts-parameters.d.ts +9 -0
  93. package/dist/src/ast/utils/write-ts-parameters.js +9 -0
  94. package/dist/src/common-results.d.ts +65 -0
  95. package/dist/src/config.d.ts +32 -0
  96. package/dist/src/config.js +5 -0
  97. package/dist/src/file-builder.d.ts +104 -0
  98. package/dist/src/file-builder.js +93 -0
  99. package/dist/src/generators/file-generator.d.ts +14 -0
  100. package/dist/src/generators/file-generator.js +9 -0
  101. package/dist/src/generators/models/model-generator.d.ts +24 -0
  102. package/dist/src/generators/models/model-generator.js +15 -0
  103. package/dist/src/generators/models/models-generator.d.ts +16 -0
  104. package/dist/src/generators/models/models-generator.js +16 -0
  105. package/dist/src/generators/models/models.d.ts +53 -0
  106. package/dist/src/generators/models/models.js +8 -0
  107. package/dist/src/generators/services/angular-services/angular-service-generator.d.ts +27 -0
  108. package/dist/src/generators/services/angular-services/angular-service-generator.js +17 -0
  109. package/dist/src/generators/services/angular-services/angular-services-generator.d.ts +21 -0
  110. package/dist/src/generators/services/angular-services/angular-services-generator.js +21 -0
  111. package/dist/src/generators/services/angular-services/models.d.ts +70 -1
  112. package/dist/src/generators/services/angular-services/models.js +5 -0
  113. package/dist/src/generators/services/angular-services/refs.d.ts +11 -0
  114. package/dist/src/generators/services/angular-services/refs.js +11 -0
  115. package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.d.ts +22 -0
  116. package/dist/src/generators/services/easy-network-stub/easy-network-stub-generator.js +12 -0
  117. package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.d.ts +16 -0
  118. package/dist/src/generators/services/easy-network-stub/easy-network-stubs-generator.js +16 -0
  119. package/dist/src/generators/services/easy-network-stub/models.d.ts +61 -0
  120. package/dist/src/generators/services/easy-network-stub/models.js +5 -0
  121. package/dist/src/generators/services/easy-network-stub/refs.d.ts +7 -0
  122. package/dist/src/generators/services/easy-network-stub/refs.js +7 -0
  123. package/dist/src/generators/services/fetch-clients/fetch-client-generator.d.ts +22 -0
  124. package/dist/src/generators/services/fetch-clients/fetch-client-generator.js +12 -0
  125. package/dist/src/generators/services/fetch-clients/fetch-clients-generator.d.ts +17 -0
  126. package/dist/src/generators/services/fetch-clients/fetch-clients-generator.js +17 -0
  127. package/dist/src/generators/services/fetch-clients/models.d.ts +64 -1
  128. package/dist/src/generators/services/fetch-clients/models.js +5 -0
  129. package/dist/src/generators/services/fetch-clients/refs.d.ts +7 -0
  130. package/dist/src/generators/services/fetch-clients/refs.js +7 -0
  131. package/dist/src/generators/services/k6-clients/k6-client-generator.d.ts +21 -0
  132. package/dist/src/generators/services/k6-clients/k6-client-generator.js +11 -0
  133. package/dist/src/generators/services/k6-clients/k6-clients-generator.d.ts +18 -0
  134. package/dist/src/generators/services/k6-clients/k6-clients-generator.js +18 -0
  135. package/dist/src/generators/services/k6-clients/models.d.ts +65 -1
  136. package/dist/src/generators/services/k6-clients/models.js +5 -0
  137. package/dist/src/generators/services/k6-clients/refs.d.ts +8 -0
  138. package/dist/src/generators/services/k6-clients/refs.js +8 -0
  139. package/dist/src/import-collection.d.ts +81 -0
  140. package/dist/src/import-collection.js +58 -0
  141. package/dist/src/utils.d.ts +62 -0
  142. package/dist/src/utils.js +47 -0
  143. package/package.json +2 -2
@@ -17,29 +17,101 @@ type _AddImportHandler<T> = {
17
17
  builderClass: abstract new (...args: any[]) => T;
18
18
  handler: (builder: T, reference: TsReference<any>) => void;
19
19
  };
20
+ /**
21
+ * Represents a reference to a named type or value, such as `Foo` or `Foo<T, U>`. A reference can also name the module
22
+ * that exports it. Writing such a reference adds an import for it to the file that is being written.
23
+ *
24
+ * The reference is written as its name, followed by the generic arguments in angle brackets when there are any. When a
25
+ * module is set and the reference is written to a `TypeScriptFileBuilder`, the name is also registered as an import of
26
+ * that file. The import is registered when the reference is written, so a reference that is never written adds no
27
+ * import. Imports from the same module are combined into one statement.
28
+ *
29
+ * How the import is written depends on `importType`. A value import is written as `import { X } from 'module';`, a type
30
+ * import as `import type { X } from 'module';`, and a `js-doc` import as an `@import` tag in a JSDoc comment, which is
31
+ * used for JavaScript output. Other builders can handle imports as well, see `registerAddImportHandler`.
32
+ *
33
+ * @template TBuilder The type of the source builder the reference is written to.
34
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
35
+ * @see tsReference
36
+ * @see TypeScriptFileBuilder
37
+ */
20
38
  export declare class TsReference<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
21
39
  private static readonly addImportHandlers;
40
+ /**
41
+ * The name of the referenced type or value, written verbatim. When a module is set, the same name is imported
42
+ * from it, so it has to be the name that the module exports.
43
+ */
22
44
  name: string;
45
+ /**
46
+ * The module name, such as `'@angular/core'`, or the path of a file that exports the name, such as
47
+ * `'./models/foo.ts'`. `null` makes the reference local, so no import is added. A path that ends in `.ts`, `.js`
48
+ * or `.json` is a file path, which is written relative to the generated file when that file's path is known.
49
+ */
23
50
  moduleNameOrfilePath: string | null;
51
+ /**
52
+ * The generic arguments written in angle brackets after the name, such as `<T, U>`. Null entries are skipped, and an
53
+ * empty list writes the bare name. With more than two arguments, each one is written on its own line.
54
+ */
24
55
  generics: TsType<TBuilder>[];
56
+ /**
57
+ * The kind of import that is added for `moduleNameOrfilePath`: `'import'` for a value import, `'type-import'` for a
58
+ * type-only import, or `'js-doc'` for an `@import` tag in a JSDoc comment. It has no effect without a module.
59
+ * @default 'import'
60
+ */
25
61
  importType: TypeScriptImportType;
62
+ /**
63
+ * Initializes a new instance of the TsReference class.
64
+ * @param options The options to use for this instance.
65
+ */
26
66
  constructor(options: Options<TBuilder, TInjects>);
27
67
  protected onWrite(builder: TBuilder): void;
68
+ /**
69
+ * Registers a handler that adds the import of a reference to builders of the given class. The handler is called
70
+ * when a reference with a module is written to a builder that is an instance of `builderClass`. Handlers are tried
71
+ * in the order they were registered, and the first one that matches is used. The default handler for
72
+ * `TypeScriptFileBuilder` is registered first, so a handler for that class, or a subclass of it, is never reached.
73
+ * @param builderClass The class of the builders that the handler applies to. Matched with `instanceof`.
74
+ * @param handler Adds the import of the reference to the builder. It receives the builder and the reference.
75
+ */
28
76
  static registerAddImportHandler<TBuilder extends SourceBuilder>(builderClass: _AddImportHandler<TBuilder>['builderClass'], handler: _AddImportHandler<TBuilder>['handler']): void;
29
77
  }
30
78
  declare const createReference: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], moduleNameOrfilePath?: Options<TBuilder>['moduleNameOrfilePath'], options?: Prettify<Omit<Options<TBuilder>, 'name' | 'moduleNameOrfilePath'>>) => TsReference<TBuilder>;
79
+ /**
80
+ * A function that creates references with a fixed name and module, as returned by `tsReference.factory`. Calling it
81
+ * creates a reference with the given options. The properties `refName` and `moduleNameOrfilePath` expose the name and
82
+ * the module that the factory was created with.
83
+ * @see tsReference.factory
84
+ */
31
85
  export type TsReferenceFactory = (<TBuilder extends SourceBuilder>(options?: FactoryOptions<TBuilder>) => TsReference<TBuilder>) & {
32
86
  refName: string;
33
87
  moduleNameOrfilePath: Nullable<string>;
34
88
  };
89
+ /**
90
+ * A reference factory that was created with a module, so its `moduleNameOrfilePath` is always a string.
91
+ * @see TsReferenceFactory
92
+ */
35
93
  export type TsModuleReferenceFactory = TsReferenceFactory & {
36
94
  moduleNameOrfilePath: string;
37
95
  };
96
+ /**
97
+ * A function that creates references to a generic type, as returned by `tsReference.genericFactory`. It takes the
98
+ * generic arguments as a tuple, whose length is given by `TGenericCount`. The `infer` function creates a reference to
99
+ * the same name without generic arguments.
100
+ *
101
+ * @template TGenericCount The number of generic arguments that are required, or an array of the accepted counts.
102
+ * @see tsReference.genericFactory
103
+ */
38
104
  export type TsGenericReferenceFactory<TGenericCount extends number | number[]> = (<TBuilder extends SourceBuilder>(generics: TupleWithCount<TsType<TBuilder>, TGenericCount>, options?: FactoryOptions<TBuilder>) => TsReference<TBuilder>) & {
39
105
  refName: string;
40
106
  moduleNameOrfilePath: Nullable<string>;
41
107
  infer: <TBuilder extends SourceBuilder>() => TsReference<TBuilder>;
42
108
  };
109
+ /**
110
+ * A generic reference factory that was created with a module, so its `moduleNameOrfilePath` is always a string.
111
+ *
112
+ * @template TGenericCount The number of generic arguments that are required, or an array of the accepted counts.
113
+ * @see TsGenericReferenceFactory
114
+ */
43
115
  export type TsGenericModuleReferenceFactory<TGenericCount extends number | number[]> = TsGenericReferenceFactory<TGenericCount> & {
44
116
  moduleNameOrfilePath: string;
45
117
  };
@@ -55,6 +127,24 @@ declare function createGenericFactory<TGenericCount extends number | number[]>(n
55
127
  declare function createGenericFactory<TGenericCount extends number | number[]>(name: string, moduleNameOrfilePath?: Nullable<string>, defaultOptions?: {
56
128
  importType?: Nullable<TypeScriptImportType>;
57
129
  }): TsGenericReferenceFactory<TGenericCount>;
130
+ /**
131
+ * Factory for creating reference nodes. The `write` function writes one or more reference nodes to a builder.
132
+ *
133
+ * `factory` creates a reusable function for a name and module, with default options. `genericFactory` does the same
134
+ * for a generic type, and takes the generic arguments as its first parameter.
135
+ *
136
+ * @param name The name of the referenced type or value. See `TsReference.name`.
137
+ * @param moduleNameOrfilePath The module or file that exports the name, or `null` for a local name.
138
+ * @param options The settings of the reference. See `TsReference` for the available properties.
139
+ * @example
140
+ * ```ts
141
+ * tsReference('X', 'module', { generics: ['T', 'U'] });
142
+ * // Output, with the import added to the file:
143
+ * // import { X } from 'module';
144
+ * // X<T, U>
145
+ * ```
146
+ * @see TsReference
147
+ */
58
148
  export declare const tsReference: typeof createReference & {
59
149
  factory: typeof createFactory;
60
150
  genericFactory: typeof createGenericFactory;
@@ -3,6 +3,24 @@ import { TypeScriptFileBuilder } from '../../file-builder.js';
3
3
  import { TsNode } from '../node.js';
4
4
  import { writeTsGenericParameters } from '../utils/write-ts-generic-parameters.js';
5
5
  import { writeTsNodes } from '../utils/write-ts-nodes.js';
6
+ /**
7
+ * Represents a reference to a named type or value, such as `Foo` or `Foo<T, U>`. A reference can also name the module
8
+ * that exports it. Writing such a reference adds an import for it to the file that is being written.
9
+ *
10
+ * The reference is written as its name, followed by the generic arguments in angle brackets when there are any. When a
11
+ * module is set and the reference is written to a `TypeScriptFileBuilder`, the name is also registered as an import of
12
+ * that file. The import is registered when the reference is written, so a reference that is never written adds no
13
+ * import. Imports from the same module are combined into one statement.
14
+ *
15
+ * How the import is written depends on `importType`. A value import is written as `import { X } from 'module';`, a type
16
+ * import as `import type { X } from 'module';`, and a `js-doc` import as an `@import` tag in a JSDoc comment, which is
17
+ * used for JavaScript output. Other builders can handle imports as well, see `registerAddImportHandler`.
18
+ *
19
+ * @template TBuilder The type of the source builder the reference is written to.
20
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
21
+ * @see tsReference
22
+ * @see TypeScriptFileBuilder
23
+ */
6
24
  export class TsReference extends TsNode {
7
25
  static addImportHandlers = [
8
26
  {
@@ -14,10 +32,32 @@ export class TsReference extends TsNode {
14
32
  },
15
33
  },
16
34
  ];
35
+ /**
36
+ * The name of the referenced type or value, written verbatim. When a module is set, the same name is imported
37
+ * from it, so it has to be the name that the module exports.
38
+ */
17
39
  name;
40
+ /**
41
+ * The module name, such as `'@angular/core'`, or the path of a file that exports the name, such as
42
+ * `'./models/foo.ts'`. `null` makes the reference local, so no import is added. A path that ends in `.ts`, `.js`
43
+ * or `.json` is a file path, which is written relative to the generated file when that file's path is known.
44
+ */
18
45
  moduleNameOrfilePath;
46
+ /**
47
+ * The generic arguments written in angle brackets after the name, such as `<T, U>`. Null entries are skipped, and an
48
+ * empty list writes the bare name. With more than two arguments, each one is written on its own line.
49
+ */
19
50
  generics;
51
+ /**
52
+ * The kind of import that is added for `moduleNameOrfilePath`: `'import'` for a value import, `'type-import'` for a
53
+ * type-only import, or `'js-doc'` for an `@import` tag in a JSDoc comment. It has no effect without a module.
54
+ * @default 'import'
55
+ */
20
56
  importType;
57
+ /**
58
+ * Initializes a new instance of the TsReference class.
59
+ * @param options The options to use for this instance.
60
+ */
21
61
  constructor(options) {
22
62
  super(options);
23
63
  this.name = options.name;
@@ -35,6 +75,14 @@ export class TsReference extends TsNode {
35
75
  }
36
76
  }
37
77
  }
78
+ /**
79
+ * Registers a handler that adds the import of a reference to builders of the given class. The handler is called
80
+ * when a reference with a module is written to a builder that is an instance of `builderClass`. Handlers are tried
81
+ * in the order they were registered, and the first one that matches is used. The default handler for
82
+ * `TypeScriptFileBuilder` is registered first, so a handler for that class, or a subclass of it, is never reached.
83
+ * @param builderClass The class of the builders that the handler applies to. Matched with `instanceof`.
84
+ * @param handler Adds the import of the reference to the builder. It receives the builder and the reference.
85
+ */
38
86
  static registerAddImportHandler(builderClass, handler) {
39
87
  TsReference.addImportHandlers.push({ builderClass, handler });
40
88
  }
@@ -59,6 +107,24 @@ function _createGenericFactory(name, moduleNameOrfilePath, defaultOptions) {
59
107
  function createGenericFactory(name, moduleNameOrfilePath, defaultOptions) {
60
108
  return _createGenericFactory(name, moduleNameOrfilePath, defaultOptions);
61
109
  }
110
+ /**
111
+ * Factory for creating reference nodes. The `write` function writes one or more reference nodes to a builder.
112
+ *
113
+ * `factory` creates a reusable function for a name and module, with default options. `genericFactory` does the same
114
+ * for a generic type, and takes the generic arguments as its first parameter.
115
+ *
116
+ * @param name The name of the referenced type or value. See `TsReference.name`.
117
+ * @param moduleNameOrfilePath The module or file that exports the name, or `null` for a local name.
118
+ * @param options The settings of the reference. See `TsReference` for the available properties.
119
+ * @example
120
+ * ```ts
121
+ * tsReference('X', 'module', { generics: ['T', 'U'] });
122
+ * // Output, with the import added to the file:
123
+ * // import { X } from 'module';
124
+ * // X<T, U>
125
+ * ```
126
+ * @see TsReference
127
+ */
62
128
  export const tsReference = Object.assign(createReference, {
63
129
  factory: createFactory,
64
130
  genericFactory: createGenericFactory,
@@ -6,13 +6,48 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
6
6
  value: string;
7
7
  template?: Nullable<boolean>;
8
8
  }>;
9
+ /**
10
+ * Represents a string literal, such as `'X'`.
11
+ *
12
+ * The value is written as a quoted literal with the escapes that a string literal needs. Strings use single quotes
13
+ * unless the `useSingleQuotes` option of the builder is turned off, in which case they use double quotes. When
14
+ * `template` is set, the value is written as a template literal between backticks instead.
15
+ *
16
+ * @template TBuilder The type of the source builder the string is written to.
17
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
18
+ * @see tsString
19
+ */
9
20
  export declare class TsString<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
21
+ /**
22
+ * The text of the string, escaped for a quoted literal. In template mode, backticks are escaped but `${` is written
23
+ * as it is, so it still starts an interpolation.
24
+ */
10
25
  value: string;
26
+ /**
27
+ * Whether the value is written as a template literal between backticks instead of a quoted string.
28
+ * @default false
29
+ */
11
30
  template: boolean;
31
+ /**
32
+ * Initializes a new instance of the TsString class.
33
+ * @param options The options to use for this instance.
34
+ */
12
35
  constructor(options: Options<TBuilder, TInjects>);
13
36
  protected onWrite(builder: TBuilder): void;
14
37
  }
15
38
  declare const createString: <TBuilder extends SourceBuilder>(value: Options<TBuilder>['value'], options?: Prettify<Omit<Options<TBuilder>, 'value'>>) => TsString<TBuilder>;
39
+ /**
40
+ * Factory for creating string nodes. The `write` function writes one or more string nodes to a builder.
41
+ *
42
+ * @param value The text of the string. See `TsString.value`.
43
+ * @param options The settings of the string. See `TsString` for the available properties.
44
+ * @example
45
+ * ```ts
46
+ * tsString('X', { template: true });
47
+ * // Emits:
48
+ * // `X`
49
+ * ```
50
+ */
16
51
  export declare const tsString: typeof createString & {
17
52
  write: typeof writeTsNodes;
18
53
  };
@@ -1,9 +1,32 @@
1
1
  import { TsNode } from '../node.js';
2
2
  import { getTypeScriptBuilderOptions } from '../utils/get-type-script-builder-options.js';
3
3
  import { writeTsNodes } from '../utils/write-ts-nodes.js';
4
+ /**
5
+ * Represents a string literal, such as `'X'`.
6
+ *
7
+ * The value is written as a quoted literal with the escapes that a string literal needs. Strings use single quotes
8
+ * unless the `useSingleQuotes` option of the builder is turned off, in which case they use double quotes. When
9
+ * `template` is set, the value is written as a template literal between backticks instead.
10
+ *
11
+ * @template TBuilder The type of the source builder the string is written to.
12
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
13
+ * @see tsString
14
+ */
4
15
  export class TsString extends TsNode {
16
+ /**
17
+ * The text of the string, escaped for a quoted literal. In template mode, backticks are escaped but `${` is written
18
+ * as it is, so it still starts an interpolation.
19
+ */
5
20
  value;
21
+ /**
22
+ * Whether the value is written as a template literal between backticks instead of a quoted string.
23
+ * @default false
24
+ */
6
25
  template;
26
+ /**
27
+ * Initializes a new instance of the TsString class.
28
+ * @param options The options to use for this instance.
29
+ */
7
30
  constructor(options) {
8
31
  super(options);
9
32
  this.value = options.value;
@@ -22,6 +45,18 @@ export class TsString extends TsNode {
22
45
  }
23
46
  }
24
47
  const createString = (value, options) => new TsString({ ...options, value });
48
+ /**
49
+ * Factory for creating string nodes. The `write` function writes one or more string nodes to a builder.
50
+ *
51
+ * @param value The text of the string. See `TsString.value`.
52
+ * @param options The settings of the string. See `TsString` for the available properties.
53
+ * @example
54
+ * ```ts
55
+ * tsString('X', { template: true });
56
+ * // Emits:
57
+ * // `X`
58
+ * ```
59
+ */
25
60
  export const tsString = Object.assign(createString, {
26
61
  write: writeTsNodes,
27
62
  });
@@ -7,13 +7,46 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
7
7
  elements: Nullable<TsType<TBuilder> | TsValue<TBuilder>>[];
8
8
  asConst?: Nullable<boolean>;
9
9
  }>;
10
+ /**
11
+ * Represents a tuple, which is a fixed list of types or values, such as `[string, number]`.
12
+ *
13
+ * Written as the elements in square brackets, separated by commas. Tuples of more than three elements are written with
14
+ * one element per line. An empty tuple is written as `[]`, and ` as const` is appended when `asConst` is set.
15
+ *
16
+ * @template TBuilder The type of the source builder the tuple is written to.
17
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
18
+ * @see tsTuple
19
+ */
10
20
  export declare class TsTuple<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
21
+ /**
22
+ * The types or values of the elements, in the given order. Null entries are skipped.
23
+ */
11
24
  elements: (TsType<TBuilder> | TsValue<TBuilder>)[];
25
+ /**
26
+ * Whether ` as const` is appended after the brackets, such as `[string, number] as const`.
27
+ * @default false
28
+ */
12
29
  asConst: boolean;
30
+ /**
31
+ * Initializes a new instance of the TsTuple class.
32
+ * @param options The options to use for this instance.
33
+ */
13
34
  constructor(options: Options<TBuilder, TInjects>);
14
35
  protected onWrite(builder: TBuilder): void;
15
36
  }
16
37
  declare const createTuple: <TBuilder extends SourceBuilder>(elements: Options<TBuilder>['elements'], options?: Prettify<Omit<Options<TBuilder>, 'elements'>>) => TsTuple<TBuilder>;
38
+ /**
39
+ * Factory for creating tuple nodes. The `write` function writes one or more tuple nodes to a builder.
40
+ *
41
+ * @param elements The types or values of the elements. See `TsTuple.elements`.
42
+ * @param options The settings of the tuple. See `TsTuple` for the available properties.
43
+ * @example
44
+ * ```ts
45
+ * tsTuple(['string', 'number'], { asConst: true });
46
+ * // Emits:
47
+ * // [string, number] as const
48
+ * ```
49
+ */
17
50
  export declare const tsTuple: typeof createTuple & {
18
51
  write: typeof writeTsNodes;
19
52
  };
@@ -1,9 +1,30 @@
1
1
  import { notNullish } from '@goast/core';
2
2
  import { TsNode } from '../node.js';
3
3
  import { writeTsNodes } from '../utils/write-ts-nodes.js';
4
+ /**
5
+ * Represents a tuple, which is a fixed list of types or values, such as `[string, number]`.
6
+ *
7
+ * Written as the elements in square brackets, separated by commas. Tuples of more than three elements are written with
8
+ * one element per line. An empty tuple is written as `[]`, and ` as const` is appended when `asConst` is set.
9
+ *
10
+ * @template TBuilder The type of the source builder the tuple is written to.
11
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
12
+ * @see tsTuple
13
+ */
4
14
  export class TsTuple extends TsNode {
15
+ /**
16
+ * The types or values of the elements, in the given order. Null entries are skipped.
17
+ */
5
18
  elements;
19
+ /**
20
+ * Whether ` as const` is appended after the brackets, such as `[string, number] as const`.
21
+ * @default false
22
+ */
6
23
  asConst;
24
+ /**
25
+ * Initializes a new instance of the TsTuple class.
26
+ * @param options The options to use for this instance.
27
+ */
7
28
  constructor(options) {
8
29
  super(options);
9
30
  this.elements = options.elements.filter(notNullish);
@@ -25,6 +46,18 @@ export class TsTuple extends TsNode {
25
46
  }
26
47
  }
27
48
  const createTuple = (elements, options) => new TsTuple({ ...options, elements });
49
+ /**
50
+ * Factory for creating tuple nodes. The `write` function writes one or more tuple nodes to a builder.
51
+ *
52
+ * @param elements The types or values of the elements. See `TsTuple.elements`.
53
+ * @param options The settings of the tuple. See `TsTuple` for the available properties.
54
+ * @example
55
+ * ```ts
56
+ * tsTuple(['string', 'number'], { asConst: true });
57
+ * // Emits:
58
+ * // [string, number] as const
59
+ * ```
60
+ */
28
61
  export const tsTuple = Object.assign(createTuple, {
29
62
  write: writeTsNodes,
30
63
  });
@@ -12,16 +12,60 @@ type Options<TBuilder extends SourceBuilder, TInjects extends string = never> =
12
12
  type: TsType<TBuilder>;
13
13
  export?: Nullable<boolean>;
14
14
  }>;
15
+ /**
16
+ * Represents a type alias declaration, such as `export type X<T> = T | null;`.
17
+ *
18
+ * Written in this order: doc comment, `export` keyword, `type`, name, generics, ` = `, the type, and a semicolon. A
19
+ * type that spans several lines is indented. Unlike classes and methods, the doc comment is written as it is, so the
20
+ * descriptions of the generic parameters are not added to it as `@template` tags.
21
+ *
22
+ * @template TBuilder The type of the source builder the type alias is written to.
23
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
24
+ * @see tsTypeAlias
25
+ */
15
26
  export declare class TsTypeAlias<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
27
+ /**
28
+ * The name of the type alias, written verbatim after the `type` keyword.
29
+ */
16
30
  name: string;
31
+ /**
32
+ * The doc comment written above the declaration, or `null` to omit it. It is written as given.
33
+ */
17
34
  doc: TsDoc<TBuilder> | null;
35
+ /**
36
+ * The type parameters written in angle brackets after the name, such as `<T, U>`. Null entries are skipped.
37
+ */
18
38
  generics: (TsGenericParameter<TBuilder> | BasicAppendValue<TBuilder>)[];
39
+ /**
40
+ * The aliased type, written after ` = `. It is required.
41
+ */
19
42
  type: TsType<TBuilder>;
43
+ /**
44
+ * Whether the declaration is written with the `export` keyword.
45
+ * @default false
46
+ */
20
47
  export: boolean;
48
+ /**
49
+ * Initializes a new instance of the TsTypeAlias class.
50
+ * @param options The options to use for this instance.
51
+ */
21
52
  constructor(options: Options<TBuilder, TInjects>);
22
53
  protected onWrite(builder: TBuilder): void;
23
54
  }
24
55
  declare const createTypeAlias: <TBuilder extends SourceBuilder>(name: Options<TBuilder>['name'], type: Options<TBuilder>['type'], options?: Prettify<Omit<Options<TBuilder>, 'name' | 'type'>>) => TsTypeAlias<TBuilder>;
56
+ /**
57
+ * Factory for creating type alias nodes. The `write` function writes one or more type alias nodes to a builder.
58
+ *
59
+ * @param name The name of the type alias. See `TsTypeAlias.name`.
60
+ * @param type The aliased type. See `TsTypeAlias.type`.
61
+ * @param options The settings of the type alias. See `TsTypeAlias` for the available properties.
62
+ * @example
63
+ * ```ts
64
+ * tsTypeAlias('X', 'number', { export: true });
65
+ * // Emits:
66
+ * // export type X = number;
67
+ * ```
68
+ */
25
69
  export declare const tsTypeAlias: typeof createTypeAlias & {
26
70
  write: typeof writeTsNodes;
27
71
  };
@@ -2,12 +2,43 @@ import { notNullish, } from '@goast/core';
2
2
  import { TsNode } from '../node.js';
3
3
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
4
4
  import { tsGenericParameter } from './generic-parameter.js';
5
+ /**
6
+ * Represents a type alias declaration, such as `export type X<T> = T | null;`.
7
+ *
8
+ * Written in this order: doc comment, `export` keyword, `type`, name, generics, ` = `, the type, and a semicolon. A
9
+ * type that spans several lines is indented. Unlike classes and methods, the doc comment is written as it is, so the
10
+ * descriptions of the generic parameters are not added to it as `@template` tags.
11
+ *
12
+ * @template TBuilder The type of the source builder the type alias is written to.
13
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
14
+ * @see tsTypeAlias
15
+ */
5
16
  export class TsTypeAlias extends TsNode {
17
+ /**
18
+ * The name of the type alias, written verbatim after the `type` keyword.
19
+ */
6
20
  name;
21
+ /**
22
+ * The doc comment written above the declaration, or `null` to omit it. It is written as given.
23
+ */
7
24
  doc;
25
+ /**
26
+ * The type parameters written in angle brackets after the name, such as `<T, U>`. Null entries are skipped.
27
+ */
8
28
  generics;
29
+ /**
30
+ * The aliased type, written after ` = `. It is required.
31
+ */
9
32
  type;
33
+ /**
34
+ * Whether the declaration is written with the `export` keyword.
35
+ * @default false
36
+ */
10
37
  export;
38
+ /**
39
+ * Initializes a new instance of the TsTypeAlias class.
40
+ * @param options The options to use for this instance.
41
+ */
11
42
  constructor(options) {
12
43
  super(options);
13
44
  this.name = options.name;
@@ -33,6 +64,19 @@ export class TsTypeAlias extends TsNode {
33
64
  }
34
65
  }
35
66
  const createTypeAlias = (name, type, options) => new TsTypeAlias({ ...options, name, type });
67
+ /**
68
+ * Factory for creating type alias nodes. The `write` function writes one or more type alias nodes to a builder.
69
+ *
70
+ * @param name The name of the type alias. See `TsTypeAlias.name`.
71
+ * @param type The aliased type. See `TsTypeAlias.type`.
72
+ * @param options The settings of the type alias. See `TsTypeAlias` for the available properties.
73
+ * @example
74
+ * ```ts
75
+ * tsTypeAlias('X', 'number', { export: true });
76
+ * // Emits:
77
+ * // export type X = number;
78
+ * ```
79
+ */
36
80
  export const tsTypeAlias = Object.assign(createTypeAlias, {
37
81
  write: writeTsNodes,
38
82
  });
@@ -6,12 +6,53 @@ type Injects = 'value';
6
6
  type Options<TBuilder extends SourceBuilder, TInjects extends string = never> = AstNodeOptions<typeof TsNode<TBuilder, TInjects | Injects>, {
7
7
  value: TsValue<TBuilder>;
8
8
  }>;
9
+ /**
10
+ * Represents a `typeof` type query, which takes the type of a value, such as `typeof foo`.
11
+ *
12
+ * Written as the keyword `typeof` followed by the value. The injection points `beforeValue` and `afterValue` wrap the
13
+ * value.
14
+ *
15
+ * @template TBuilder The type of the source builder the type query is written to.
16
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
17
+ * @see tsTypeof
18
+ */
9
19
  export declare class TsTypeof<TBuilder extends SourceBuilder, TInjects extends string = never> extends TsNode<TBuilder, TInjects | Injects> {
20
+ /**
21
+ * The value whose type is queried, written after `typeof`, such as `foo`.
22
+ */
10
23
  value: TsValue<TBuilder>;
24
+ /**
25
+ * Initializes a new instance of the TsTypeof class.
26
+ * @param options The options to use for this instance.
27
+ */
11
28
  constructor(options: Options<TBuilder, TInjects>);
12
29
  protected onWrite(builder: TBuilder): void;
13
30
  }
31
+ /**
32
+ * Creates a `typeof` type query node. This is the function that `tsTypeof` wraps, and `tsTypeof` also provides `write`.
33
+ *
34
+ * @param value The value whose type is queried. See `TsTypeof.value`.
35
+ * @param options The settings of the type query. See `TsTypeof` for the available properties.
36
+ * @example
37
+ * ```ts
38
+ * createTypeof('foo');
39
+ * // Emits:
40
+ * // typeof foo
41
+ * ```
42
+ */
14
43
  export declare const createTypeof: <TBuilder extends SourceBuilder>(value: Options<TBuilder>['value'], options?: Omit<Options<TBuilder>, 'value'>) => TsTypeof<TBuilder>;
44
+ /**
45
+ * Factory for creating `typeof` type query nodes. The `write` function writes one or more of them to a builder.
46
+ *
47
+ * @param value The value whose type is queried. See `TsTypeof.value`.
48
+ * @param options The settings of the type query. See `TsTypeof` for the available properties.
49
+ * @example
50
+ * ```ts
51
+ * tsTypeof('foo');
52
+ * // Emits:
53
+ * // typeof foo
54
+ * ```
55
+ */
15
56
  export declare const tsTypeof: typeof createTypeof & {
16
57
  write: typeof writeTsNodes;
17
58
  };
@@ -1,7 +1,24 @@
1
1
  import { TsNode } from '../node.js';
2
2
  import { writeTsNode, writeTsNodes } from '../utils/write-ts-nodes.js';
3
+ /**
4
+ * Represents a `typeof` type query, which takes the type of a value, such as `typeof foo`.
5
+ *
6
+ * Written as the keyword `typeof` followed by the value. The injection points `beforeValue` and `afterValue` wrap the
7
+ * value.
8
+ *
9
+ * @template TBuilder The type of the source builder the type query is written to.
10
+ * @template TInjects Additional names of custom injection points (`before*` and `after*`) accepted by this node.
11
+ * @see tsTypeof
12
+ */
3
13
  export class TsTypeof extends TsNode {
14
+ /**
15
+ * The value whose type is queried, written after `typeof`, such as `foo`.
16
+ */
4
17
  value;
18
+ /**
19
+ * Initializes a new instance of the TsTypeof class.
20
+ * @param options The options to use for this instance.
21
+ */
5
22
  constructor(options) {
6
23
  super(options);
7
24
  this.value = options.value;
@@ -13,7 +30,31 @@ export class TsTypeof extends TsNode {
13
30
  builder.append(this.inject.afterValue);
14
31
  }
15
32
  }
33
+ /**
34
+ * Creates a `typeof` type query node. This is the function that `tsTypeof` wraps, and `tsTypeof` also provides `write`.
35
+ *
36
+ * @param value The value whose type is queried. See `TsTypeof.value`.
37
+ * @param options The settings of the type query. See `TsTypeof` for the available properties.
38
+ * @example
39
+ * ```ts
40
+ * createTypeof('foo');
41
+ * // Emits:
42
+ * // typeof foo
43
+ * ```
44
+ */
16
45
  export const createTypeof = (value, options) => new TsTypeof({ ...options, value });
46
+ /**
47
+ * Factory for creating `typeof` type query nodes. The `write` function writes one or more of them to a builder.
48
+ *
49
+ * @param value The value whose type is queried. See `TsTypeof.value`.
50
+ * @param options The settings of the type query. See `TsTypeof` for the available properties.
51
+ * @example
52
+ * ```ts
53
+ * tsTypeof('foo');
54
+ * // Emits:
55
+ * // typeof foo
56
+ * ```
57
+ */
17
58
  export const tsTypeof = Object.assign(createTypeof, {
18
59
  write: writeTsNodes,
19
60
  });