dart-lang / dart-lang/language

Syntactic sugar for `typedef`

Open
#4,112 8 comments 1 reaction 0 assignees View on GitHub
feature
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

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
```dart
class Random {}

// Other things that our code might use
class A {}
```

main.dart
```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:

```dart
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.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing Dart's import combinators, `typedef` syntax, and the ambiguity example in the issue. Determine the accepted syntax and its interaction with `show`, `hide`, and imported elements; done means the language design is resolved and specified consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.