The syntax for narrowing the type of a value is prefix is Type val
, for example:
void takeOnlyStrings(String* s) {
print(s);
}
{String|Integer*} ab = {"Hi", 1};
takeOnlyStrings(for (item in ab) if (is String item) item);
The syntax item is String
is just an operator expression that produces a Boolean
value. It doesn't narrow the type of its argument.