Before of the latest update, i wrote this code for example
<input type="text" id="link">
<p> {{variable}} </p>
// other code
var input = query('#link');
var variable = input.value;
This snippet of code still work, but anyone know why the editor reports this message?
"value" in not a member of Element
The Dart Editor reports that, because it thinks
inputvariable is an instance ofElement. Why? Becausequery()always returns an element, but the editor can’t know that in your case, it’s an input (of typeInputElement).You can ignore the warning. The IDE just can’t know that the queried result is an
InputElement, unless you tell it:or I think this also works:
If you really want to tell the Dart runtime that you expect a variable to be of a certain type, you can use the cast operator:
as. This has the advantage of informing the editor of the expected type, and it will also throw an error if the variable is not of the expected type.Note that Dart is a dynamic language, so I caution against using
asunless you think other developers might be confused about your intent.