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

LegendPosition enum break template type checks #1955

Open
kschaefe opened this issue Apr 22, 2024 · 0 comments
Open

LegendPosition enum break template type checks #1955

kschaefe opened this issue Apr 22, 2024 · 0 comments
Labels

Comments

@kschaefe
Copy link

Describe the bug
Angular's fullTemplateTypeCheck wants the passed type of LegendPosition to be a value from the enum. Passing in the string that represents that value causes the compiler to reject the string. You have the

To Reproduce
Manually set the LegendPosition to a string, such as right or below and compile with fullTemplateTypeCheck. You'll get an error like

Building Angular Package

------------------------------------------------------------------------------
Building entry point 'livelab'
------------------------------------------------------------------------------
✖ Compiling with Angular sources in Ivy partial compilation mode.
projects/livelab/src/lib/student-details/livelab-student-details.component.html:127:49 - error TS2322: Type '"below"' is not assignable to type 'LegendPosition'.

127             [legend]="true" [legendTitle]="''" [legendPosition]="'below'" [yScaleMax]="yScaleMax" [yScaleMin]="0"
                                                    ~~~~~~~~~~~~~~

  projects/livelab/src/lib/student-details/livelab-student-details.component.ts:33:16
    33   templateUrl: "./livelab-student-details.component.html",
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component LivelabStudentDetailsComponent.

Expected behavior
Unfortunately, this is the expected behavior because enums are bad. You want, per your documentation, that value to be a string, but it's not. The source code should be:

export type LegendPosition = 'right' | 'below';

ngx-charts version
Present on any version that uses LegendPosition enum. Experienced on 20.5.0.

Additional context
You can work around this issue using Angular's $any(), but then why enable strict type checking?

Ideally, you'd similarly convert any other enums to a union of string literals, which is almost always better anyway. I, however, only attempted to use this enum.

@kschaefe kschaefe added the Bug label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant