Is there a way of getting the type of a variable in Typescript?
I know:
typeof
operator, but it only returns type in the primitive level, e.g. "string", "object", "boolean"instanceof
only work for a class, when the variable is defined bylet myVar = new Class()
once compiled to javascript, these
type
s andinterface
s are gone, as they are only for Typescript to do static type-checking.
But if I have the following, how can I show a
has a type of interface A
?
interface A {
title: string,
description: string,
}
const a: A = { title: "my title", description: "my description" }
// cmd so it shows `a` is of `interface A`
console.log(...)
The reason I think there must be a way but just that I don't know how because a properly configured editor can show the variable type (at Typescript level) when the cursor is moved to the variable.
Thanks