language
language copied to clipboard
Syntactic sugar for `typedef`
Today if I have two libraries that export classes with the same name, we get ambiguous_import
if we try to use it. The suggested workarounds are to add an alias to one (or both) imports or to use hide
.
Most of the time this is just fine, I'd like to propose a syntactic sugar to make the class names clearer on use.
Today we can do the following:
a.dart
class Random {}
// Other things that our code might use
class A {}
main.dart
import 'dart:math';
import 'a.dart' as a show Random;
import 'a.dart' hide Random;
typedef MyRandom = a.Random;
A? aInstance;
MyRandom? myRandom;
Random? random;
I'd like to propose a syntactic sugar for imported elements:
import 'dart:math';
import 'a.dart' with Random as MyRandom;
I'm not sure what word to use on with
, just a suggestion. Using a different word to mean that I don't want to show
or hide
anything, but I believe this should work on show
as well.