From 8164fb65130bc7acf005a94b5147546161bcba46 Mon Sep 17 00:00:00 2001 From: Andreas Kunz Date: Tue, 10 Sep 2024 08:04:21 +0200 Subject: [PATCH] fix(ts-interface-generator): fix return type of removeAggregation (#471) fixes #470 --- packages/ts-interface-generator/package.json | 2 +- .../src/astGenerationHelper.ts | 11 +- .../src/test/generateMethods.test.ts | 2 +- .../test/interfaceGenerationHelper.test.ts | 4 +- .../sampleControl/SampleControl.gen.d.ts | 4 +- .../SampleWebComponent.gen.d.ts | 1438 ++++++++--------- .../ts-interface-generator/src/types.d.ts | 2 +- yarn.lock | 38 +- 8 files changed, 742 insertions(+), 759 deletions(-) diff --git a/packages/ts-interface-generator/package.json b/packages/ts-interface-generator/package.json index d3cd1fc..3605eb6 100644 --- a/packages/ts-interface-generator/package.json +++ b/packages/ts-interface-generator/package.json @@ -38,7 +38,7 @@ "@types/hjson": "2.4.6", "@types/jest": "29.5.12", "@types/node": "20.14.9", - "@types/openui5": "1.117.0", + "@types/openui5": "1.127.0", "@types/yargs": "17.0.32", "@typescript-eslint/eslint-plugin": "7.14.1", "@typescript-eslint/parser": "7.14.1", diff --git a/packages/ts-interface-generator/src/astGenerationHelper.ts b/packages/ts-interface-generator/src/astGenerationHelper.ts index 0843015..728ffb5 100644 --- a/packages/ts-interface-generator/src/astGenerationHelper.ts +++ b/packages/ts-interface-generator/src/astGenerationHelper.ts @@ -579,7 +579,16 @@ function generateMethods( ]), ), ], - factory.createThisTypeNode(), + factory.createUnionTypeNode([ + // the removed child or null if not found + createTSTypeNode( + aggregation.type, + requiredImports, + knownGlobals, + currentClassName, + ), + factory.createLiteralTypeNode(ts.factory.createNull()), + ]), ); addJSDocCommentToNode( remove, diff --git a/packages/ts-interface-generator/src/test/generateMethods.test.ts b/packages/ts-interface-generator/src/test/generateMethods.test.ts index 86f1900..7a478fc 100644 --- a/packages/ts-interface-generator/src/test/generateMethods.test.ts +++ b/packages/ts-interface-generator/src/test/generateMethods.test.ts @@ -40,7 +40,7 @@ test("Generate methods for aggregation", () => { getContent(): Control[]; addContent(content: Control): this; insertContent(content: Control, index: number): this; -removeContent(content: number | string | Control): this; +removeContent(content: number | string | Control): Control | null; removeAllContent(): Control[]; indexOfContent(content: Control): number; destroyContent(): this; diff --git a/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts b/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts index 6ba9a3b..ecb3c47 100644 --- a/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts +++ b/packages/ts-interface-generator/src/test/interfaceGenerationHelper.test.ts @@ -188,7 +188,7 @@ declare module "./SampleControl" { * @param content The content to remove or its index or id * @returns The removed content or "null" */ - removeContent(content: number | string | Control): this; + removeContent(content: number | string | Control): Control | null; /** * Removes all the controls from the aggregation "content". @@ -511,7 +511,7 @@ declare module "./SampleControl" { * @param content The content to remove or its index or id * @returns The removed content or "null" */ - removeContent(content: number | string | Control): this; + removeContent(content: number | string | Control): Control | null; /** * Removes all the controls from the aggregation "content". diff --git a/packages/ts-interface-generator/src/test/testdata/sampleControl/SampleControl.gen.d.ts b/packages/ts-interface-generator/src/test/testdata/sampleControl/SampleControl.gen.d.ts index 16eba76..1185e1a 100644 --- a/packages/ts-interface-generator/src/test/testdata/sampleControl/SampleControl.gen.d.ts +++ b/packages/ts-interface-generator/src/test/testdata/sampleControl/SampleControl.gen.d.ts @@ -142,7 +142,7 @@ declare module "./SampleControl" { * @param content The content to remove or its index or id * @returns The removed content or "null" */ - removeContent(content: number | string | Control): this; + removeContent(content: number | string | Control): Control | null; /** * Removes all the controls from the aggregation "content". @@ -465,7 +465,7 @@ declare module "./SampleControl" { * @param content The content to remove or its index or id * @returns The removed content or "null" */ - removeContent(content: number | string | Control): this; + removeContent(content: number | string | Control): Control | null; /** * Removes all the controls from the aggregation "content". diff --git a/packages/ts-interface-generator/src/test/testdata/sampleWebComponent/SampleWebComponent.gen.d.ts b/packages/ts-interface-generator/src/test/testdata/sampleWebComponent/SampleWebComponent.gen.d.ts index cf61e08..ed4bf70 100644 --- a/packages/ts-interface-generator/src/test/testdata/sampleWebComponent/SampleWebComponent.gen.d.ts +++ b/packages/ts-interface-generator/src/test/testdata/sampleWebComponent/SampleWebComponent.gen.d.ts @@ -8,748 +8,722 @@ import { PropertyBindingInfo } from "sap/ui/base/ManagedObject"; import { $WebComponentSettings } from "sap/ui/core/webc/WebComponent"; declare module "./SampleWebComponent" { - /** - * Interface defining the settings object used in constructor calls - */ - interface $SampleWebComponentSettings extends $WebComponentSettings { - /** - * The text that appears below the main text. - * - * @since 1.0 - */ - subtext?: string | PropertyBindingInfo; - - /** - * Determines the text color of the SampleWebComponent. - * - * @experimental - */ - textColor?: CSSColor | PropertyBindingInfo | `{${string}}`; - - /** - * Usage of mapping - */ - text?: string | PropertyBindingInfo; - - /** - * Determines the content of the SampleWebComponent. - */ - content?: Control[] | Control | AggregationBindingInfo | `{${string}}`; - header?: WebComponent; - tooltip?: TooltipBase | string | PropertyBindingInfo; - partnerControl?: SampleWebComponent | string; - - /** - * This is an association. - */ - alsoLabelledBy?: Control | string | (Control | string)[]; /** + * Interface defining the settings object used in constructor calls + */ + interface $SampleWebComponentSettings extends $WebComponentSettings { + + /** + * The text that appears below the main text. + * + * @since 1.0 + */ + subtext?: string | PropertyBindingInfo; + + /** + * Determines the text color of the SampleWebComponent. + * + * @experimental + */ + textColor?: CSSColor | PropertyBindingInfo | `{${string}}`; + + /** + * Usage of mapping + */ + text?: string | PropertyBindingInfo; + + /** + * Determines the content of the SampleWebComponent. + */ + content?: Control[] | Control | AggregationBindingInfo | `{${string}}`; + header?: WebComponent; + tooltip?: TooltipBase | string | PropertyBindingInfo; + partnerControl?: SampleWebComponent | string; + + /** + * This is an association. + */ + alsoLabelledBy?: Control | string | (Control | string)[]; + + /** + * Fired when double-clicked. + */ + doublePress?: (event: SampleWebComponent$DoublePressEvent) => void; + } + + export default interface SampleWebComponent { + + // property: subtext + + /** + * Gets current value of property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * + * @returns Value of property "subtext" + */ + getSubtext(): string; + + /** + * Sets a new value for property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param subtext New value for property "subtext" + * @returns Reference to "this" in order to allow method chaining + */ + setSubtext(subtext: string): this; + + // property: textColor + + /** + * Gets current value of property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * Default value is: "" + * @returns Value of property "textColor" + */ + getTextColor(): CSSColor; + + /** + * Sets a new value for property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * Default value is: "" + * @param [textColor=""] New value for property "textColor" + * @returns Reference to "this" in order to allow method chaining + */ + setTextColor(textColor: CSSColor): this; + + // property: text + + /** + * Gets current value of property "text". + * + * Usage of mapping + * + * @returns Value of property "text" + */ + getText(): string; + + /** + * Sets a new value for property "text". + * + * Usage of mapping + * + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param text New value for property "text" + * @returns Reference to "this" in order to allow method chaining + */ + setText(text: string): this; + + // aggregation: content + + /** + * Gets content of aggregation "content". + * + * Determines the content of the SampleWebComponent. + */ + getContent(): Control[]; + + /** + * Adds some content to the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addContent(content: Control): this; + + /** + * Inserts a content into the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to insert; if empty, nothing is inserted + * @param index The "0"-based index the content should be inserted at; for + * a negative value of "iIndex", the content is inserted at position 0; for a value + * greater than the current size of the aggregation, the content is inserted at + * the last position + * @returns Reference to "this" in order to allow method chaining + */ + insertContent(content: Control, index: number): this; + + /** + * Removes a content from the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to remove or its index or id + * @returns The removed content or "null" + */ + removeContent(content: number | string | Control): Control | null; + + /** + * Removes all the controls from the aggregation "content". + * Additionally, it unregisters them from the hosting UIArea. + * + * Determines the content of the SampleWebComponent. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllContent(): Control[]; + + /** + * Checks for the provided "sap.ui.core.Control" in the aggregation "content". + * and returns its index if found or -1 otherwise. + * + * Determines the content of the SampleWebComponent. + * + * @param content The content whose index is looked for + * @returns The index of the provided control in the aggregation if found, or -1 otherwise + */ + indexOfContent(content: Control): number; + + /** + * Destroys all the content in the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyContent(): this; + + /** + * Binds aggregation "content" to model data. + * + * Determines the content of the SampleWebComponent. + * + * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a + * detailed description of the possible properties of "oBindingInfo". + * @param oBindingInfo The binding information + * @returns Reference to "this" in order to allow method chaining + */ + bindContent(bindingInfo: AggregationBindingInfo): this; + + /** + * Unbinds aggregation "content" from model data. + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + unbindContent(): this; + + // aggregation: header + + /** + * Gets content of aggregation "header". + */ + getHeader(): WebComponent; + + /** + * Sets the aggregated header. + * + * @param header The header to set + * @returns Reference to "this" in order to allow method chaining + */ + setHeader(header: WebComponent): this; + + /** + * Destroys the header in the aggregation "header". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyHeader(): this; + + // aggregation: tooltip + + /** + * Gets content of aggregation "tooltip". + */ + getTooltip(): TooltipBase; + + /** + * Sets the aggregated tooltip. + * + * @param tooltip The tooltip to set + * @returns Reference to "this" in order to allow method chaining + */ + setTooltip(tooltip: TooltipBase): this; + + /** + * Destroys the tooltip in the aggregation "tooltip". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyTooltip(): this; + + // association: partnerControl + + /** + * ID of the element which is the current target of the association "partnerControl", or "null". + */ + getPartnerControl(): string; + + /** + * Sets the associated partnerControl. + * + * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given + * @returns Reference to "this" in order to allow method chaining + */ + setPartnerControl(partnerControl?: string | SampleWebComponent): this; + + // association: alsoLabelledBy + + /** + * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". + * + * This is an association. + */ + getAlsoLabelledBy(): string[]; + + /** + * Adds some alsoLabelledBy into the association "alsoLabelledBy". + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addAlsoLabelledBy(alsoLabelledBy: string | Control): this; + + /** + * Removes an alsoLabelledBy from the association named alsoLabelledBy. + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID + * @returns The removed alsoLabelledBy or "null" + */ + removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; + + /** + * Removes all the controls in the association named alsoLabelledBy. + * + * This is an association. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllAlsoLabelledBy(): string[]; + + // event: doublePress + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(data: CustomDataType, fn: (event: SampleWebComponent$DoublePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Fires event "doublePress" to attached listeners. + * + * Fired when double-clicked. + * + * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. + * The return value of this method indicates whether the default action should be executed. + * + * @param parameters Parameters to pass along with the event + * @returns Whether or not to prevent the default action + */ + fireDoublePress(parameters?: SampleWebComponent$DoublePressEventParameters): boolean; + } + + /** + * Interface describing the parameters of SampleWebComponent's 'doublePress' event. * Fired when double-clicked. */ - doublePress?: (event: SampleWebComponent$DoublePressEvent) => void; - } - - export default interface SampleWebComponent { - // property: subtext - - /** - * Gets current value of property "subtext". - * - * The text that appears below the main text. - * - * @since 1.0 - * - * @returns Value of property "subtext" - */ - getSubtext(): string; - - /** - * Sets a new value for property "subtext". - * - * The text that appears below the main text. - * - * @since 1.0 - * When called with a value of "null" or "undefined", the default value of the property will be restored. - * - * @param subtext New value for property "subtext" - * @returns Reference to "this" in order to allow method chaining - */ - setSubtext(subtext: string): this; - - // property: textColor - - /** - * Gets current value of property "textColor". - * - * Determines the text color of the SampleWebComponent. - * - * @experimental - * Default value is: "" - * @returns Value of property "textColor" - */ - getTextColor(): CSSColor; - - /** - * Sets a new value for property "textColor". - * - * Determines the text color of the SampleWebComponent. - * - * @experimental - * When called with a value of "null" or "undefined", the default value of the property will be restored. - * - * Default value is: "" - * @param [textColor=""] New value for property "textColor" - * @returns Reference to "this" in order to allow method chaining - */ - setTextColor(textColor: CSSColor): this; - - // property: text - - /** - * Gets current value of property "text". - * - * Usage of mapping - * - * @returns Value of property "text" - */ - getText(): string; - - /** - * Sets a new value for property "text". - * - * Usage of mapping - * - * When called with a value of "null" or "undefined", the default value of the property will be restored. - * - * @param text New value for property "text" - * @returns Reference to "this" in order to allow method chaining - */ - setText(text: string): this; - - // aggregation: content - - /** - * Gets content of aggregation "content". - * - * Determines the content of the SampleWebComponent. - */ - getContent(): Control[]; - - /** - * Adds some content to the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @param content The content to add; if empty, nothing is inserted - * @returns Reference to "this" in order to allow method chaining - */ - addContent(content: Control): this; + // eslint-disable-next-line + export interface SampleWebComponent$DoublePressEventParameters { + } /** - * Inserts a content into the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @param content The content to insert; if empty, nothing is inserted - * @param index The "0"-based index the content should be inserted at; for - * a negative value of "iIndex", the content is inserted at position 0; for a value - * greater than the current size of the aggregation, the content is inserted at - * the last position - * @returns Reference to "this" in order to allow method chaining - */ - insertContent(content: Control, index: number): this; - - /** - * Removes a content from the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @param content The content to remove or its index or id - * @returns The removed content or "null" - */ - removeContent(content: number | string | Control): this; - - /** - * Removes all the controls from the aggregation "content". - * Additionally, it unregisters them from the hosting UIArea. - * - * Determines the content of the SampleWebComponent. - * - * @returns An array of the removed elements (might be empty) - */ - removeAllContent(): Control[]; - - /** - * Checks for the provided "sap.ui.core.Control" in the aggregation "content". - * and returns its index if found or -1 otherwise. - * - * Determines the content of the SampleWebComponent. - * - * @param content The content whose index is looked for - * @returns The index of the provided control in the aggregation if found, or -1 otherwise - */ - indexOfContent(content: Control): number; - - /** - * Destroys all the content in the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @returns Reference to "this" in order to allow method chaining - */ - destroyContent(): this; - - /** - * Binds aggregation "content" to model data. - * - * Determines the content of the SampleWebComponent. - * - * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a - * detailed description of the possible properties of "oBindingInfo". - * @param oBindingInfo The binding information - * @returns Reference to "this" in order to allow method chaining - */ - bindContent(bindingInfo: AggregationBindingInfo): this; - - /** - * Unbinds aggregation "content" from model data. - * - * Determines the content of the SampleWebComponent. - * - * @returns Reference to "this" in order to allow method chaining - */ - unbindContent(): this; - - // aggregation: header - - /** - * Gets content of aggregation "header". - */ - getHeader(): WebComponent; - - /** - * Sets the aggregated header. - * - * @param header The header to set - * @returns Reference to "this" in order to allow method chaining - */ - setHeader(header: WebComponent): this; - - /** - * Destroys the header in the aggregation "header". - * - * @returns Reference to "this" in order to allow method chaining - */ - destroyHeader(): this; - - // aggregation: tooltip - - /** - * Gets content of aggregation "tooltip". - */ - getTooltip(): TooltipBase; - - /** - * Sets the aggregated tooltip. - * - * @param tooltip The tooltip to set - * @returns Reference to "this" in order to allow method chaining - */ - setTooltip(tooltip: TooltipBase): this; - - /** - * Destroys the tooltip in the aggregation "tooltip". - * - * @returns Reference to "this" in order to allow method chaining - */ - destroyTooltip(): this; - - // association: partnerControl - - /** - * ID of the element which is the current target of the association "partnerControl", or "null". - */ - getPartnerControl(): string; - - /** - * Sets the associated partnerControl. - * - * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given - * @returns Reference to "this" in order to allow method chaining - */ - setPartnerControl(partnerControl?: string | SampleWebComponent): this; - - // association: alsoLabelledBy - - /** - * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". - * - * This is an association. - */ - getAlsoLabelledBy(): string[]; - - /** - * Adds some alsoLabelledBy into the association "alsoLabelledBy". - * - * This is an association. - * - * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted - * @returns Reference to "this" in order to allow method chaining - */ - addAlsoLabelledBy(alsoLabelledBy: string | Control): this; - - /** - * Removes an alsoLabelledBy from the association named alsoLabelledBy. - * - * This is an association. - * - * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID - * @returns The removed alsoLabelledBy or "null" - */ - removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; - - /** - * Removes all the controls in the association named alsoLabelledBy. - * - * This is an association. - * - * @returns An array of the removed elements (might be empty) - */ - removeAllAlsoLabelledBy(): string[]; - - // event: doublePress - - /** - * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". - * + * Type describing the SampleWebComponent's 'doublePress' event. * Fired when double-clicked. - * - * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, - * otherwise it will be bound to this "SampleWebComponent" itself. - * - * @param fn The function to be called when the event occurs - * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself - * - * @returns Reference to "this" in order to allow method chaining */ - attachDoublePress( - fn: (event: SampleWebComponent$DoublePressEvent) => void, - listener?: object - ): this; - - /** - * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". - * - * Fired when double-clicked. - * - * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, - * otherwise it will be bound to this "SampleWebComponent" itself. - * - * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event - * @param fn The function to be called when the event occurs - * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself - * - * @returns Reference to "this" in order to allow method chaining - */ - attachDoublePress( - data: CustomDataType, - fn: ( - event: SampleWebComponent$DoublePressEvent, - data: CustomDataType - ) => void, - listener?: object - ): this; - - /** - * Detaches event handler "fn" from the "doublePress" event of this "SampleWebComponent". - * - * Fired when double-clicked. - * - * The passed function and listener object must match the ones used for event registration. - * - * @param fn The function to be called, when the event occurs - * @param listener Context object on which the given function had to be called - * @returns Reference to "this" in order to allow method chaining - */ - detachDoublePress( - fn: (event: SampleWebComponent$DoublePressEvent) => void, - listener?: object - ): this; - - /** - * Fires event "doublePress" to attached listeners. - * - * Fired when double-clicked. - * - * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. - * The return value of this method indicates whether the default action should be executed. - * - * @param parameters Parameters to pass along with the event - * @returns Whether or not to prevent the default action - */ - fireDoublePress( - parameters?: SampleWebComponent$DoublePressEventParameters - ): boolean; - } - - /** - * Interface describing the parameters of SampleWebComponent's 'doublePress' event. - * Fired when double-clicked. - */ - // eslint-disable-next-line - export interface SampleWebComponent$DoublePressEventParameters {} - - /** - * Type describing the SampleWebComponent's 'doublePress' event. - * Fired when double-clicked. - */ - export type SampleWebComponent$DoublePressEvent = - Event; + export type SampleWebComponent$DoublePressEvent = Event; } // this duplicate interface without export is needed to avoid "Cannot find name 'SampleWebComponent'" TypeScript errors above declare module "./SampleWebComponent" { - interface SampleWebComponent { - // property: subtext - - /** - * Gets current value of property "subtext". - * - * The text that appears below the main text. - * - * @since 1.0 - * - * @returns Value of property "subtext" - */ - getSubtext(): string; - - /** - * Sets a new value for property "subtext". - * - * The text that appears below the main text. - * - * @since 1.0 - * When called with a value of "null" or "undefined", the default value of the property will be restored. - * - * @param subtext New value for property "subtext" - * @returns Reference to "this" in order to allow method chaining - */ - setSubtext(subtext: string): this; - - // property: textColor - - /** - * Gets current value of property "textColor". - * - * Determines the text color of the SampleWebComponent. - * - * @experimental - * Default value is: "" - * @returns Value of property "textColor" - */ - getTextColor(): CSSColor; - - /** - * Sets a new value for property "textColor". - * - * Determines the text color of the SampleWebComponent. - * - * @experimental - * When called with a value of "null" or "undefined", the default value of the property will be restored. - * - * Default value is: "" - * @param [textColor=""] New value for property "textColor" - * @returns Reference to "this" in order to allow method chaining - */ - setTextColor(textColor: CSSColor): this; - - // property: text - - /** - * Gets current value of property "text". - * - * Usage of mapping - * - * @returns Value of property "text" - */ - getText(): string; - - /** - * Sets a new value for property "text". - * - * Usage of mapping - * - * When called with a value of "null" or "undefined", the default value of the property will be restored. - * - * @param text New value for property "text" - * @returns Reference to "this" in order to allow method chaining - */ - setText(text: string): this; - - // aggregation: content - - /** - * Gets content of aggregation "content". - * - * Determines the content of the SampleWebComponent. - */ - getContent(): Control[]; - - /** - * Adds some content to the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @param content The content to add; if empty, nothing is inserted - * @returns Reference to "this" in order to allow method chaining - */ - addContent(content: Control): this; - - /** - * Inserts a content into the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @param content The content to insert; if empty, nothing is inserted - * @param index The "0"-based index the content should be inserted at; for - * a negative value of "iIndex", the content is inserted at position 0; for a value - * greater than the current size of the aggregation, the content is inserted at - * the last position - * @returns Reference to "this" in order to allow method chaining - */ - insertContent(content: Control, index: number): this; - - /** - * Removes a content from the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @param content The content to remove or its index or id - * @returns The removed content or "null" - */ - removeContent(content: number | string | Control): this; - - /** - * Removes all the controls from the aggregation "content". - * Additionally, it unregisters them from the hosting UIArea. - * - * Determines the content of the SampleWebComponent. - * - * @returns An array of the removed elements (might be empty) - */ - removeAllContent(): Control[]; - - /** - * Checks for the provided "sap.ui.core.Control" in the aggregation "content". - * and returns its index if found or -1 otherwise. - * - * Determines the content of the SampleWebComponent. - * - * @param content The content whose index is looked for - * @returns The index of the provided control in the aggregation if found, or -1 otherwise - */ - indexOfContent(content: Control): number; - - /** - * Destroys all the content in the aggregation "content". - * - * Determines the content of the SampleWebComponent. - * - * @returns Reference to "this" in order to allow method chaining - */ - destroyContent(): this; - - /** - * Binds aggregation "content" to model data. - * - * Determines the content of the SampleWebComponent. - * - * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a - * detailed description of the possible properties of "oBindingInfo". - * @param oBindingInfo The binding information - * @returns Reference to "this" in order to allow method chaining - */ - bindContent(bindingInfo: AggregationBindingInfo): this; - - /** - * Unbinds aggregation "content" from model data. - * - * Determines the content of the SampleWebComponent. - * - * @returns Reference to "this" in order to allow method chaining - */ - unbindContent(): this; - - // aggregation: header - - /** - * Gets content of aggregation "header". - */ - getHeader(): WebComponent; - - /** - * Sets the aggregated header. - * - * @param header The header to set - * @returns Reference to "this" in order to allow method chaining - */ - setHeader(header: WebComponent): this; - - /** - * Destroys the header in the aggregation "header". - * - * @returns Reference to "this" in order to allow method chaining - */ - destroyHeader(): this; - - // aggregation: tooltip - - /** - * Gets content of aggregation "tooltip". - */ - getTooltip(): TooltipBase; - - /** - * Sets the aggregated tooltip. - * - * @param tooltip The tooltip to set - * @returns Reference to "this" in order to allow method chaining - */ - setTooltip(tooltip: TooltipBase): this; - - /** - * Destroys the tooltip in the aggregation "tooltip". - * - * @returns Reference to "this" in order to allow method chaining - */ - destroyTooltip(): this; - - // association: partnerControl - - /** - * ID of the element which is the current target of the association "partnerControl", or "null". - */ - getPartnerControl(): string; - - /** - * Sets the associated partnerControl. - * - * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given - * @returns Reference to "this" in order to allow method chaining - */ - setPartnerControl(partnerControl?: string | SampleWebComponent): this; - - // association: alsoLabelledBy - - /** - * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". - * - * This is an association. - */ - getAlsoLabelledBy(): string[]; - - /** - * Adds some alsoLabelledBy into the association "alsoLabelledBy". - * - * This is an association. - * - * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted - * @returns Reference to "this" in order to allow method chaining - */ - addAlsoLabelledBy(alsoLabelledBy: string | Control): this; - - /** - * Removes an alsoLabelledBy from the association named alsoLabelledBy. - * - * This is an association. - * - * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID - * @returns The removed alsoLabelledBy or "null" - */ - removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; - - /** - * Removes all the controls in the association named alsoLabelledBy. - * - * This is an association. - * - * @returns An array of the removed elements (might be empty) - */ - removeAllAlsoLabelledBy(): string[]; - - // event: doublePress - - /** - * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". - * - * Fired when double-clicked. - * - * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, - * otherwise it will be bound to this "SampleWebComponent" itself. - * - * @param fn The function to be called when the event occurs - * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself - * - * @returns Reference to "this" in order to allow method chaining - */ - attachDoublePress( - fn: (event: SampleWebComponent$DoublePressEvent) => void, - listener?: object - ): this; - - /** - * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". - * - * Fired when double-clicked. - * - * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, - * otherwise it will be bound to this "SampleWebComponent" itself. - * - * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event - * @param fn The function to be called when the event occurs - * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself - * - * @returns Reference to "this" in order to allow method chaining - */ - attachDoublePress( - data: CustomDataType, - fn: ( - event: SampleWebComponent$DoublePressEvent, - data: CustomDataType - ) => void, - listener?: object - ): this; - - /** - * Detaches event handler "fn" from the "doublePress" event of this "SampleWebComponent". - * - * Fired when double-clicked. - * - * The passed function and listener object must match the ones used for event registration. - * - * @param fn The function to be called, when the event occurs - * @param listener Context object on which the given function had to be called - * @returns Reference to "this" in order to allow method chaining - */ - detachDoublePress( - fn: (event: SampleWebComponent$DoublePressEvent) => void, - listener?: object - ): this; - - /** - * Fires event "doublePress" to attached listeners. - * - * Fired when double-clicked. - * - * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. - * The return value of this method indicates whether the default action should be executed. - * - * @param parameters Parameters to pass along with the event - * @returns Whether or not to prevent the default action - */ - fireDoublePress( - parameters?: SampleWebComponent$DoublePressEventParameters - ): boolean; - } + interface SampleWebComponent { + + // property: subtext + + /** + * Gets current value of property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * + * @returns Value of property "subtext" + */ + getSubtext(): string; + + /** + * Sets a new value for property "subtext". + * + * The text that appears below the main text. + * + * @since 1.0 + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param subtext New value for property "subtext" + * @returns Reference to "this" in order to allow method chaining + */ + setSubtext(subtext: string): this; + + // property: textColor + + /** + * Gets current value of property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * Default value is: "" + * @returns Value of property "textColor" + */ + getTextColor(): CSSColor; + + /** + * Sets a new value for property "textColor". + * + * Determines the text color of the SampleWebComponent. + * + * @experimental + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * Default value is: "" + * @param [textColor=""] New value for property "textColor" + * @returns Reference to "this" in order to allow method chaining + */ + setTextColor(textColor: CSSColor): this; + + // property: text + + /** + * Gets current value of property "text". + * + * Usage of mapping + * + * @returns Value of property "text" + */ + getText(): string; + + /** + * Sets a new value for property "text". + * + * Usage of mapping + * + * When called with a value of "null" or "undefined", the default value of the property will be restored. + * + * @param text New value for property "text" + * @returns Reference to "this" in order to allow method chaining + */ + setText(text: string): this; + + // aggregation: content + + /** + * Gets content of aggregation "content". + * + * Determines the content of the SampleWebComponent. + */ + getContent(): Control[]; + + /** + * Adds some content to the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addContent(content: Control): this; + + /** + * Inserts a content into the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to insert; if empty, nothing is inserted + * @param index The "0"-based index the content should be inserted at; for + * a negative value of "iIndex", the content is inserted at position 0; for a value + * greater than the current size of the aggregation, the content is inserted at + * the last position + * @returns Reference to "this" in order to allow method chaining + */ + insertContent(content: Control, index: number): this; + + /** + * Removes a content from the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @param content The content to remove or its index or id + * @returns The removed content or "null" + */ + removeContent(content: number | string | Control): Control | null; + + /** + * Removes all the controls from the aggregation "content". + * Additionally, it unregisters them from the hosting UIArea. + * + * Determines the content of the SampleWebComponent. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllContent(): Control[]; + + /** + * Checks for the provided "sap.ui.core.Control" in the aggregation "content". + * and returns its index if found or -1 otherwise. + * + * Determines the content of the SampleWebComponent. + * + * @param content The content whose index is looked for + * @returns The index of the provided control in the aggregation if found, or -1 otherwise + */ + indexOfContent(content: Control): number; + + /** + * Destroys all the content in the aggregation "content". + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyContent(): this; + + /** + * Binds aggregation "content" to model data. + * + * Determines the content of the SampleWebComponent. + * + * See {@link sap.ui.base.ManagedObject#bindAggregation ManagedObject.bindAggregation} for a + * detailed description of the possible properties of "oBindingInfo". + * @param oBindingInfo The binding information + * @returns Reference to "this" in order to allow method chaining + */ + bindContent(bindingInfo: AggregationBindingInfo): this; + + /** + * Unbinds aggregation "content" from model data. + * + * Determines the content of the SampleWebComponent. + * + * @returns Reference to "this" in order to allow method chaining + */ + unbindContent(): this; + + // aggregation: header + + /** + * Gets content of aggregation "header". + */ + getHeader(): WebComponent; + + /** + * Sets the aggregated header. + * + * @param header The header to set + * @returns Reference to "this" in order to allow method chaining + */ + setHeader(header: WebComponent): this; + + /** + * Destroys the header in the aggregation "header". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyHeader(): this; + + // aggregation: tooltip + + /** + * Gets content of aggregation "tooltip". + */ + getTooltip(): TooltipBase; + + /** + * Sets the aggregated tooltip. + * + * @param tooltip The tooltip to set + * @returns Reference to "this" in order to allow method chaining + */ + setTooltip(tooltip: TooltipBase): this; + + /** + * Destroys the tooltip in the aggregation "tooltip". + * + * @returns Reference to "this" in order to allow method chaining + */ + destroyTooltip(): this; + + // association: partnerControl + + /** + * ID of the element which is the current target of the association "partnerControl", or "null". + */ + getPartnerControl(): string; + + /** + * Sets the associated partnerControl. + * + * @param partnerControl ID of an element which becomes the new target of this "partnerControl" association; alternatively, an element instance may be given + * @returns Reference to "this" in order to allow method chaining + */ + setPartnerControl(partnerControl?: string | SampleWebComponent): this; + + // association: alsoLabelledBy + + /** + * Returns array of IDs of the elements which are the current targets of the association "alsoLabelledBy". + * + * This is an association. + */ + getAlsoLabelledBy(): string[]; + + /** + * Adds some alsoLabelledBy into the association "alsoLabelledBy". + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to add; if empty, nothing is inserted + * @returns Reference to "this" in order to allow method chaining + */ + addAlsoLabelledBy(alsoLabelledBy: string | Control): this; + + /** + * Removes an alsoLabelledBy from the association named alsoLabelledBy. + * + * This is an association. + * + * @param alsoLabelledBy The alsoLabelledBy to be removed or its index or ID + * @returns The removed alsoLabelledBy or "null" + */ + removeAlsoLabelledBy(alsoLabelledBy: number | string | Control): string; + + /** + * Removes all the controls in the association named alsoLabelledBy. + * + * This is an association. + * + * @returns An array of the removed elements (might be empty) + */ + removeAllAlsoLabelledBy(): string[]; + + // event: doublePress + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Attaches event handler "fn" to the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * When called, the context of the event handler (its "this") will be bound to "oListener" if specified, + * otherwise it will be bound to this "SampleWebComponent" itself. + * + * @param data An application-specific payload object that will be passed to the event handler along with the event object when firing the event + * @param fn The function to be called when the event occurs + * @param listener Context object to call the event handler with. Defaults to this "SampleWebComponent" itself + * + * @returns Reference to "this" in order to allow method chaining + */ + attachDoublePress(data: CustomDataType, fn: (event: SampleWebComponent$DoublePressEvent, data: CustomDataType) => void, listener?: object): this; + + /** + * Detaches event handler "fn" from the "doublePress" event of this "SampleWebComponent". + * + * Fired when double-clicked. + * + * The passed function and listener object must match the ones used for event registration. + * + * @param fn The function to be called, when the event occurs + * @param listener Context object on which the given function had to be called + * @returns Reference to "this" in order to allow method chaining + */ + detachDoublePress(fn: (event: SampleWebComponent$DoublePressEvent) => void, listener?: object): this; + + /** + * Fires event "doublePress" to attached listeners. + * + * Fired when double-clicked. + * + * Listeners may prevent the default action of this event by calling the "preventDefault" method on the event object. + * The return value of this method indicates whether the default action should be executed. + * + * @param parameters Parameters to pass along with the event + * @returns Whether or not to prevent the default action + */ + fireDoublePress(parameters?: SampleWebComponent$DoublePressEventParameters): boolean; + } } diff --git a/packages/ts-interface-generator/src/types.d.ts b/packages/ts-interface-generator/src/types.d.ts index c6853c8..e433c0d 100644 --- a/packages/ts-interface-generator/src/types.d.ts +++ b/packages/ts-interface-generator/src/types.d.ts @@ -48,7 +48,7 @@ interface Property extends APIMemberWithMethods, APIMemberWithType { interface Aggregation extends APIMemberWithMethods, APIMemberWithType { cardinality: "0..1" | "0..n"; - altTypes: [string]; + altTypes: [string] | null; //dnd: any, singularName: string; bindable: boolean; diff --git a/yarn.lock b/yarn.lock index b416296..ec4aa40 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1606,13 +1606,6 @@ expect "^29.0.0" pretty-format "^29.0.0" -"@types/jquery@*": - version "3.5.30" - resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.30.tgz#888d584cbf844d3df56834b69925085038fd80f7" - integrity sha512-nbWKkkyb919DOUxjmRVk8vwtDb0/k8FKncmUKFi+NY+QXqWltooxTrswvz4LspQwxvLdvzBN1TImr6cw3aQx2A== - dependencies: - "@types/sizzle" "*" - "@types/jquery@3.5.13": version "3.5.13" resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.13.tgz#5482d3ee325d5862f77a91c09369ae0a5b082bf3" @@ -1620,6 +1613,13 @@ dependencies: "@types/sizzle" "*" +"@types/jquery@~3.5.13": + version "3.5.30" + resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.30.tgz#888d584cbf844d3df56834b69925085038fd80f7" + integrity sha512-nbWKkkyb919DOUxjmRVk8vwtDb0/k8FKncmUKFi+NY+QXqWltooxTrswvz4LspQwxvLdvzBN1TImr6cw3aQx2A== + dependencies: + "@types/sizzle" "*" + "@types/json5@^0.0.29": version "0.0.29" resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" @@ -1659,24 +1659,24 @@ resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz#56e2cc26c397c038fab0e3a917a12d5c5909e901" integrity sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA== -"@types/openui5@1.117.0": - version "1.117.0" - resolved "https://registry.yarnpkg.com/@types/openui5/-/openui5-1.117.0.tgz#24525e588717a20f915c77c26c1412150439dc40" - integrity sha512-cSrT++FOAVQbjxnosbaqjiEEq67LSkCc0U+PwPDtZhqiLPQ8otFWJTZGXMj4kqookmeO9fSRZGnxCGRPlPmNuA== +"@types/openui5@1.127.0": + version "1.127.0" + resolved "https://registry.yarnpkg.com/@types/openui5/-/openui5-1.127.0.tgz#4b84a5fd721a3cfda3d9e3445a38f705626e2a2a" + integrity sha512-MIauyuHgaNnN7PDMZ71vS9XqpVlo0tXL6EaMhdmNjQTMblm6IJxlmOz0UX1BkdJwGKIA2rVE+2WGz6xn7ndJaQ== dependencies: - "@types/jquery" "*" - "@types/qunit" "*" - -"@types/qunit@*": - version "2.19.10" - resolved "https://registry.yarnpkg.com/@types/qunit/-/qunit-2.19.10.tgz#ab859a76a1e6aadcba45d20d6d6307cd1fc11a01" - integrity sha512-gVB+rxvxmbyPFWa6yjjKgcumWal3hyqoTXI0Oil161uWfo1OCzWZ/rnEumsx+6uVgrwPrCrhpQbLkzfildkSbg== + "@types/jquery" "~3.5.13" + "@types/qunit" "^2.5.4" "@types/qunit@2.5.4": version "2.5.4" resolved "https://registry.yarnpkg.com/@types/qunit/-/qunit-2.5.4.tgz#0518940acc6013259a8619a1ec34ce0e4ff8d1c4" integrity sha512-VHi2lEd4/zp8OOouf43JXGJJ5ZxHvdLL1dU0Yakp6Iy73SjpuXl7yjwAwmh1qhTv8krDgHteSwaySr++uXX9YQ== +"@types/qunit@^2.5.4": + version "2.19.10" + resolved "https://registry.yarnpkg.com/@types/qunit/-/qunit-2.19.10.tgz#ab859a76a1e6aadcba45d20d6d6307cd1fc11a01" + integrity sha512-gVB+rxvxmbyPFWa6yjjKgcumWal3hyqoTXI0Oil161uWfo1OCzWZ/rnEumsx+6uVgrwPrCrhpQbLkzfildkSbg== + "@types/sanitize-html@2.11.0": version "2.11.0" resolved "https://registry.yarnpkg.com/@types/sanitize-html/-/sanitize-html-2.11.0.tgz#582d8c72215c0228e3af2be136e40e0b531addf2" @@ -1793,7 +1793,7 @@ eslint-visitor-keys "^3.4.3" "@ui5/dts-generator@link:packages/dts-generator": - version "3.1.0" + version "3.3.0" dependencies: "@definitelytyped/dtslint" latest "@definitelytyped/eslint-plugin" latest