dart-lang / language

Design of the Dart language
Other
2.67k stars 205 forks source link

Add show as to import stmt. #1708

Open heckad opened 3 years ago

heckad commented 3 years ago

Motivation: Sometimes different packages have the same public names.

Exmaple

import 'package:firebase_auth/firebase_auth.dart'
    show FirebaseAuth, User as FirebaseUser, FirebaseAuthException;
munificent commented 3 years ago

You can already use as for the entire library in order to disambiguate colliding names:

import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;
import 'other_library_with_user.dart' as other;

main() {
  var user1 = firebase_auth.User();
  var user2 = other.User();
}

With non-function type aliases, you can also do:

import 'package:firebase_auth/firebase_auth.dart' as firebase_auth;

typedef User = firebase_auth.FirebaseUser;

Given that, I think it's unlikely to be worth supporting renaming on import too, though it's conceivably something we could do.