Skip to content

Commit

Permalink
fix: take the changed enum representation into account for array types (
Browse files Browse the repository at this point in the history
#483)

When deciding between the array notations Some[] and Array<Some>, take
the new way of representing enum return types into account.

A method

  getSticky(): Array<Sticky | keyof typeof Sticky>

now should be represented as

  getSticky(): Sticky[]
  • Loading branch information
codeworrior authored Jan 8, 2025
1 parent a34cee0 commit 1a1a660
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/dts-generator/src/phases/dts-code-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,9 @@ function genTypeDefinition(
* @param ast
* @returns
*/
function hasSimpleElementType(ast: ArrayType): boolean {
function hasSimpleElementType(ast: ArrayType, usage = "unknown"): boolean {
if (ast.elementType.kind === "ArrayType") {
return hasSimpleElementType(ast.elementType);
return hasSimpleElementType(ast.elementType, usage);
}
// TODO TypeReference with import type should be handled in json-to-ast
// (requires re-write of GlobalsVisitor#visitTypeName and its callers)
Expand All @@ -796,7 +796,7 @@ function hasSimpleElementType(ast: ArrayType): boolean {
(!ast.elementType.typeArguments ||
ast.elementType.typeArguments.length === 0) &&
!ast.elementType.typeName.startsWith("import(") &&
!ast.elementType.isStandardEnum
(!ast.elementType.isStandardEnum || usage === "returnValue")
);
}
return false;
Expand Down Expand Up @@ -828,7 +828,7 @@ function genType(ast: Type, usage: string = "unknown"): string {
}
return text;
case "ArrayType":
if (hasSimpleElementType(ast)) {
if (hasSimpleElementType(ast, usage)) {
return `${genType(ast.elementType, usage)}[]`;
}
return `Array<${genType(ast.elementType, usage)}>`;
Expand Down
8 changes: 4 additions & 4 deletions test-packages/openui5-snapshot-test/output-dts/sap.m.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48303,7 +48303,7 @@ declare module "sap/m/ListBase" {
*
* @returns Value of property `sticky`
*/
getSticky(): Array<Sticky>;
getSticky(): Sticky[];
/**
* Gets content of aggregation {@link #getSwipeContent swipeContent}.
*
Expand Down Expand Up @@ -73769,7 +73769,7 @@ declare module "sap/m/P13nConditionPanel" {
* defines the type for which the operations should be returned.
*/
sType?: string
): Array<P13nConditionOperation>;
): P13nConditionOperation[];
/**
* Gets current value of property {@link #getShowLabel showLabel}.
*
Expand Down Expand Up @@ -76273,7 +76273,7 @@ declare module "sap/m/P13nFilterPanel" {
* the type for which the operations are defined
*/
sType: string
): Array<P13nConditionOperation>;
): P13nConditionOperation[];
/**
* Gets content of aggregation {@link #getFilterItems filterItems}.
*
Expand Down Expand Up @@ -129975,7 +129975,7 @@ declare module "sap/m/Table" {
*
* @returns Value of property `hiddenInPopin`
*/
getHiddenInPopin(): Array<Priority>;
getHiddenInPopin(): Priority[];
/**
* Gets current value of property {@link #getPopinLayout popinLayout}.
*
Expand Down

0 comments on commit 1a1a660

Please sign in to comment.