Component: Dialog position variable rejects string values as incorrect type #13906
Labels
Status: Needs Triage
Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Describe the bug
When using the p-dialog component, I tried to set the position dynamically as shown in the example documentation. However, the following error occurs:
error TS2322: Type 'string' is not assignable to type '"center" | "top" | "bottom" | "left" | "right" | "topleft" | "topright" | "bottomleft" | "bottomright"'.
Template code:
<p-dialog [(visible)]="isModalVisible" [modal]="true" [breakpoints]="{ '768px': '95vw' }" [style]="{ width: '50vw' }" [draggable]="false" [resizable]="false" [position]="position">
TypeScript code:
public position: string = 'center';
To fix the issue, I need to add the position string type union (or a subset) into my code:
value: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright'
However this should not be necessary and is also in contradiction to the documentation that a string is valid.
Environment
Angular 16 application
Reproducer
No response
Angular version
16.1.5
PrimeNG version
16.3.1
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
16.20.1
Browser(s)
No response
Steps to reproduce the behavior
The easiest way to reproduce is to replicate the code verbatim from the Dialog documentation here https://primeng.org/dialog#position
Alternatively:
p-dialog
tag on a component template[position]="position"
to the p-dialogposition: string = 'center';
ng serve
The error can be circumvented by adding type unions to the variable but this should not be necessary:
position: 'center' | 'top' = 'center'
Expected behavior
String variables with a valid position value can be assigned to the [position] attribute on p-dialog.
The text was updated successfully, but these errors were encountered: