[FIXED] How to properly access "dynamic" added properties on Objects on Angular strict mode?

Issue

I’m using PrimeNG (Angular) and under the strict mode, one of its documentation case is this:

if (window['Prism']) {
...any code
}

The VSCode shows me this: Element implicitly has an 'any' type because index expression is not of type 'number'.

But I don’t know how to bypass this error..

Solution

I’d cast window to unknown first like this

(window as unknown).Prism

https://mariusschulz.com/blog/the-unknown-type-in-typescript

Answered By – Mr Smith

Answer Checked By – David Goodson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published