How can I get the type of an initial value expression of a field using Dart's analyzer API?
class MyClass {
var prop = <initial value expression>;
}
If initial value expression is for example 'text', I'd like to get String. If it is a function call, I'd like to get the return type of the function.
After getting a fully resolved AST structure, ask the
Expressionrepresenting the initial value expression for it'sstaticType. That will return theDartTyperepresenting the static type.It's possible for type inference to produce a more specialized type, which you can access using
propagatedType. (And if you don't care which type you get, you can usebestType.