dart-lang / dart-lang/language
"Infer this type" for explicit generic types.
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
What I'm thinking is simple. In the case where a function or class has multiple generic parameters, we should be allowed to explicitly say that the type system should infer the other arguments on its own. For example:
```dart
class ChangeNotifier {
Prop select(Prop Function(Obj) selector) => selector(this);
}
void main() {
var notifier = // code that gets a notifier.
/// For instance, this [name] property can be a String, so it's inferred as [notifier.select(...)]
var name = notifier.select((m) => m.name);
/// Another possibility:
var name = notifier.select((m) => m.name);
}
```
I guess we can always just specify the type in the closure itself, but it might still prove useful in other constructs. For now, this is what I find myself using it most for.
Contributor guide
Research direction
Start with the proposal and examples in issue #3510; no source files or tests are named. Investigate how explicit generic arguments and inference are specified in the Dart language repository, then determine the intended semantics and specification changes needed for the feature.
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
- 25/100