Skip to content

Commit 1a1a660

Browse files
authored
fix: take the changed enum representation into account for array types (#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[]
1 parent a34cee0 commit 1a1a660

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/dts-generator/src/phases/dts-code-gen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,9 @@ function genTypeDefinition(
785785
* @param ast
786786
* @returns
787787
*/
788-
function hasSimpleElementType(ast: ArrayType): boolean {
788+
function hasSimpleElementType(ast: ArrayType, usage = "unknown"): boolean {
789789
if (ast.elementType.kind === "ArrayType") {
790-
return hasSimpleElementType(ast.elementType);
790+
return hasSimpleElementType(ast.elementType, usage);
791791
}
792792
// TODO TypeReference with import type should be handled in json-to-ast
793793
// (requires re-write of GlobalsVisitor#visitTypeName and its callers)
@@ -796,7 +796,7 @@ function hasSimpleElementType(ast: ArrayType): boolean {
796796
(!ast.elementType.typeArguments ||
797797
ast.elementType.typeArguments.length === 0) &&
798798
!ast.elementType.typeName.startsWith("import(") &&
799-
!ast.elementType.isStandardEnum
799+
(!ast.elementType.isStandardEnum || usage === "returnValue")
800800
);
801801
}
802802
return false;
@@ -828,7 +828,7 @@ function genType(ast: Type, usage: string = "unknown"): string {
828828
}
829829
return text;
830830
case "ArrayType":
831-
if (hasSimpleElementType(ast)) {
831+
if (hasSimpleElementType(ast, usage)) {
832832
return `${genType(ast.elementType, usage)}[]`;
833833
}
834834
return `Array<${genType(ast.elementType, usage)}>`;

test-packages/openui5-snapshot-test/output-dts/sap.m.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48303,7 +48303,7 @@ declare module "sap/m/ListBase" {
4830348303
*
4830448304
* @returns Value of property `sticky`
4830548305
*/
48306-
getSticky(): Array<Sticky>;
48306+
getSticky(): Sticky[];
4830748307
/**
4830848308
* Gets content of aggregation {@link #getSwipeContent swipeContent}.
4830948309
*
@@ -73769,7 +73769,7 @@ declare module "sap/m/P13nConditionPanel" {
7376973769
* defines the type for which the operations should be returned.
7377073770
*/
7377173771
sType?: string
73772-
): Array<P13nConditionOperation>;
73772+
): P13nConditionOperation[];
7377373773
/**
7377473774
* Gets current value of property {@link #getShowLabel showLabel}.
7377573775
*
@@ -76273,7 +76273,7 @@ declare module "sap/m/P13nFilterPanel" {
7627376273
* the type for which the operations are defined
7627476274
*/
7627576275
sType: string
76276-
): Array<P13nConditionOperation>;
76276+
): P13nConditionOperation[];
7627776277
/**
7627876278
* Gets content of aggregation {@link #getFilterItems filterItems}.
7627976279
*
@@ -129975,7 +129975,7 @@ declare module "sap/m/Table" {
129975129975
*
129976129976
* @returns Value of property `hiddenInPopin`
129977129977
*/
129978-
getHiddenInPopin(): Array<Priority>;
129978+
getHiddenInPopin(): Priority[];
129979129979
/**
129980129980
* Gets current value of property {@link #getPopinLayout popinLayout}.
129981129981
*

0 commit comments

Comments
 (0)