|
1 | 1 | import { printId } from "../../formatter/print/printer.js"; |
| 2 | +import { isTemplateInstance } from "../type-utils.js"; |
2 | 3 | import { |
3 | 4 | Enum, |
4 | 5 | Interface, |
@@ -39,7 +40,7 @@ export function getTypeName(type: Type, options?: TypeNameOptions): string { |
39 | 40 | case "Union": |
40 | 41 | return type.name |
41 | 42 | ? getIdentifierName(type.name, options) |
42 | | - : type.options.map((x) => getTypeName(x, options)).join(" | "); |
| 43 | + : [...type.variants.values()].map((x) => getTypeName(x.type, options)).join(" | "); |
43 | 44 | case "UnionVariant": |
44 | 45 | return getTypeName(type.type, options); |
45 | 46 | case "Tuple": |
@@ -119,9 +120,9 @@ function getModelName(model: Model, options: TypeNameOptions | undefined) { |
119 | 120 | return nsPrefix + "(anonymous model)"; |
120 | 121 | } |
121 | 122 | const modelName = nsPrefix + getIdentifierName(model.name, options); |
122 | | - if (model.templateArguments && model.templateArguments.length > 0) { |
| 123 | + if (isTemplateInstance(model)) { |
123 | 124 | // template instantiation |
124 | | - const args = model.templateArguments.map((x) => getTypeName(x, options)); |
| 125 | + const args = model.templateMapper.args.map((x) => getTypeName(x, options)); |
125 | 126 | return `${modelName}<${args.join(", ")}>`; |
126 | 127 | } else if ((model.node as ModelStatementNode)?.templateParameters?.length > 0) { |
127 | 128 | // template |
@@ -159,8 +160,10 @@ function getModelPropertyName(prop: ModelProperty, options: TypeNameOptions | un |
159 | 160 |
|
160 | 161 | function getInterfaceName(iface: Interface, options: TypeNameOptions | undefined) { |
161 | 162 | let interfaceName = getIdentifierName(iface.name, options); |
162 | | - if (iface.templateArguments && iface.templateArguments.length > 0) { |
163 | | - interfaceName += `<${iface.templateArguments.map((x) => getTypeName(x, options)).join(", ")}>`; |
| 163 | + if (isTemplateInstance(iface)) { |
| 164 | + interfaceName += `<${iface.templateMapper.args |
| 165 | + .map((x) => getTypeName(x, options)) |
| 166 | + .join(", ")}>`; |
164 | 167 | } |
165 | 168 | return `${getNamespacePrefix(iface.namespace, options)}${interfaceName}`; |
166 | 169 | } |
|
0 commit comments