Is there a way to distinguish between a class (not its instance!) and a function in TypeScript during runtime.
Normally classes in typescript are transpiled to javascript functions and during runtime I could not find a nice way to check whether an identifier is a function or a class type!
For example:
function func1() {
}
class class1 {
}
// ugly hack
(<any>class1.prototype).isclass = true;
// ugly hack test
function is_class(clazz:any) {
return (
clazz
&& clazz.prototype
&& (<any>clazz.prototype).isclass === true
);
}
console.log(typeof(func1) === 'function'); // returns true !!
console.log(typeof(class1) === 'function'); // returns true !!
console.log(is_class(func1)); // returns false :)
console.log(is_class(class1)); // returns true :)
Any ideas for a better solution? Thanks.