I am implementing an interface with a method that looks like:
Update(Payload: any): void
I would like to type cast the payload to different types and depending on if the type cast succeeds, take some sort of action.
However, I’m hitting the error: “dynamic cast argument type ‘any’ must be a class”.
It seems like dynamic type casting is only supported for class instances. Is there a way to type my Payload parameter to signify that it is guaranteed to be a class?
Yeah I thought about making a generic base class for all of my custom classes, but just feels bad haha. Plenty of workarounds, just wish that some of these language features were more flexible
Yes I agree, but I think that it will be improved one day, as they say it themselves that this type lacks uses (c.f. doc)
There is very little that you can do with an any type. but it’s good to be aware of this type as it may come up when writing code that produces an error.