You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the p-table component with a custom body template, and binding the $implicit to let-product, the product variable has the type any.
It would be good if we could somehow automatically set the type of $implicit to the row type.
Why is this useful
Types would have the benefit of ensuring consistency in updates of PrimeNG and Angular itself and would enable code completion.
Example
I have forked the basic Table example from the documentation, and edited the output of the first column to point to a non-existent property.
I would expect that the angular build fails with a compilation error. But it does build sucessfully without any problem, because the type of the product variable is any.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Problem
When using the p-table component with a custom body template, and binding the $implicit to
let-product
, theproduct
variable has the typeany
.It would be good if we could somehow automatically set the type of
$implicit
to the row type.Why is this useful
Types would have the benefit of ensuring consistency in updates of PrimeNG and Angular itself and would enable code completion.
Example
I have forked the basic Table example from the documentation, and edited the output of the first column to point to a non-existent property.
I would expect that the angular build fails with a compilation error. But it does build sucessfully without any problem, because the type of the
product
variable isany
.https://stackblitz.com/edit/jmmphv?file=src%2Fapp%2Ftable-basic-demo.html
Workaround
There is a workaround by Alain Boudard on medium.com, where he uses an additional custom directive on the
ng-template
for the body, which overrides the context: https://coco-boudard.medium.com/typing-angular-primeng-templates-7c2851f76c39But in my opinion, PrimeNG should set the correct type automatically, by defining a correct templateContext instead of
any
.Beta Was this translation helpful? Give feedback.
All reactions