From 3d872c11fa6e8bd9be3750cce1a8d42458064d30 Mon Sep 17 00:00:00 2001 From: Davide Mininni <101575400+DavideMininni-Fincons@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:48:56 +0100 Subject: [PATCH] feat: add class generic type param in manifest (#3292) The datepicker and the calendar components use generic type parameter to allow custom implementation of Date, eg. ``` export class SbbDatepickerElement { private _min?: T | null; // and so on } ``` This needs to be taken in account in Angular classes generation, so a new param has been added to the manifest during its generation, eg. ``` { "kind": "javascript-module", "path": "datepicker/datepicker.js", "declarations": [ { "kind": "class", "description": "Combined with a native input, it displays the input's value as a formatted date.", "name": "SbbDatepickerElement", "members": [], "events": [], "attributes": [], "superclass": {}, "classGenerics": "T = Date", <--------------------------------- new property "tagName": "sbb-datepicker", "customElement": true } ], exports: [] ``` --- .../manifest/custom-elements-manifest.config.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tools/manifest/custom-elements-manifest.config.js b/tools/manifest/custom-elements-manifest.config.js index 8dcb6b15cd..398f5fddd2 100644 --- a/tools/manifest/custom-elements-manifest.config.js +++ b/tools/manifest/custom-elements-manifest.config.js @@ -1,4 +1,5 @@ const overrideTypeKey = 'overrideType'; +const classGenericsTypeKey = 'classGenerics'; /** * Docs: https://custom-elements-manifest.open-wc.org/analyzer/getting-started/ @@ -96,6 +97,19 @@ export function createManifestConfig(library = '') { } if (ts.isClassDeclaration(node)) { + const classDeclaration = moduleDoc.declarations.find( + (declaration) => declaration.name === node.name.getText(), + ); + + /** + * If the class uses a generic type parameter, add it to the class declaration. + * It will be used in the Angular wrapper to correctly generate classes. + * Mainly used for datepicker and calendar components. + */ + if (node.typeParameters && node.typeParameters.length > 0) { + classDeclaration[classGenericsTypeKey] = node.typeParameters[0].getText(); + } + /** * When a generic T type is used in a superclass declaration, it overrides the type defined in derived class * during the doc generation (as the `value` property in the `SbbFormAssociatedMixinType`). @@ -109,9 +123,6 @@ export function createManifestConfig(library = '') { // eslint-disable-next-line lyne/local-name-rule if (tag.tagName.getText() === overrideTypeKey) { const [memberName, memberOverrideType] = tag.comment.split(' - '); - const classDeclaration = moduleDoc.declarations.find( - (declaration) => declaration.name === node.name.getText(), - ); if (!classDeclaration[overrideTypeKey]) { classDeclaration[overrideTypeKey] = [{ memberName, memberOverrideType }]; } else {