There may be some obscure reason that this is not a good idea or even possible but it would be nice to be able to do the following:
var string = 'hello';
var int = 1;
print(int is string.runtimeType);
Or be able to save a type in a variable and use it later:
var string = 'hello';
var int = 1;
var aType = string.runtimeType;
print(int is aType);
This produces a pretty silly error:
Error: 'aType' isn't a type.
Is there a difference between types and the type class?
This has been considered before in various forms (e.g. as an extension to Type API https://github.com/dart-lang/sdk/issues/30717 or as permitting expressions on the right hand side of is).
In general the only argument against this is based on the estimated code size impact, because compiler looses a good way to estimate which type checks can occur in the program - and thus can no longer throw away some of the metadata associated with the class hierarchy. @rakudrama has done experiment for dart2js to estimate approximate impact and saw some non negligible costs in terms of the code size.
Most helpful comment
This has been considered before in various forms (e.g. as an extension to
TypeAPI https://github.com/dart-lang/sdk/issues/30717 or as permitting expressions on the right hand side ofis).In general the only argument against this is based on the estimated code size impact, because compiler looses a good way to estimate which type checks can occur in the program - and thus can no longer throw away some of the metadata associated with the class hierarchy. @rakudrama has done experiment for dart2js to estimate approximate impact and saw some non negligible costs in terms of the code size.