Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve null/undefined type handling for Angular wrapper #3302

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

DavideMininni-Fincons
Copy link
Contributor

Changes are related to Angular wrapper's classes generation.

  • sbb-calendar: normalized null / undefined types for getters and setters; needs some fix for the sbb-datepicker-toggle
  • sbb-navigation-action-common: updated mixin type
  • sbb-slider: normalized type
  • sbb-stepper: some minor fix to normalize null values, which are already considered in the existing logic but not in typings
  • sbb-tag-group: normalized type
  • sbb-time-input: add null as type as in the getter

@github-actions github-actions bot added target: 2.x pr: peer review required A peer review is required for this pull request labels Dec 16, 2024
@@ -91,7 +91,7 @@ class SbbTagGroupElement extends SbbNamedSlotListMixin<SbbTagElement, typeof Lit
? this.tags.filter((t) => t.checked).map((t) => t.value)
: (this.tags.find((t) => t.checked)?.value ?? null);
}
private _value: string | string[] | null = null;
private _value: string | (string | null)[] | null = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can that be happen, an array consisting of null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value comes from the form-associated mixin, and it's nullable, so technically yes if all the tags have no value

@@ -58,7 +58,7 @@ class SbbTagGroupElement extends SbbNamedSlotListMixin<SbbTagElement, typeof Lit
* If set multiple to true, the value is an array.
*/
@property()
public set value(value: string | string[] | null) {
public set value(value: string | (string | null)[] | null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks weird, do we expect that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just kept the same type of the getter because it seems that the manifest takes the prop types from the getter (see the other comment on the tag-group about nullability)

@@ -37,8 +37,8 @@ class SbbStepperElement extends SbbHydrationMixin(LitElement) {

/** Overrides the behaviour of `orientation` property. */
@property({ attribute: 'horizontal-from', reflect: true })
public set horizontalFrom(value: SbbHorizontalFrom) {
this._horizontalFrom = breakpoints.includes(value) ? value : undefined;
public set horizontalFrom(value: SbbHorizontalFrom | undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we do it with null (for all changes in this file)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to null would require more changes (eg. default value for horizontal-from, change the SbbStepValidateEventDetails to match the nullable and so on)

@@ -21,7 +21,7 @@ export declare class SbbNavigationActionCommonElementMixinType {
public accessor size: SbbNavigationActionSize;
public get marker(): SbbNavigationMarkerElement | null;
public get section(): SbbNavigationSectionElement | null;
public connectedSection: SbbNavigationSectionElement | null;
public connectedSection: SbbNavigationSectionElement | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the problem with null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the manifest the type is SbbNavigationSectionElement | undefined because is taken from the mixin getter, while the generated component has null because uses the MixinType;
so when i create the setter in Angular I have a type mismatch

src/elements/slider/slider.ts Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pr3302 December 16, 2024 14:24 Inactive
@github-actions github-actions bot temporarily deployed to pr3302-diff December 16, 2024 14:24 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants