I am currently working on developing a function with this structure:
function isInstance<T>(s: T): T | boolean {
return (s instanceof T) && s;
}
The purpose of this function is to return the value as that type if it is an instance, otherwise it returns false.
When I attempt to compile this code, I encounter the following error message:
'T' only refers to a type, but is being used as a value here.
My understanding is that I need to pass a T
there in order to determine if it is of that type. However, TypeScript types do not exist at runtime which could be causing the issue. I am unsure of an alternative solution that would work in this case.