-
Notifications
You must be signed in to change notification settings - Fork 225
Description
In Dart, we can tell other users of a library that they should create a class with certain methods by providing an interface. We can't tell users to create a function with certain arguments.
A use case is something like Cloud Functions, where we know the top-level function must have a certain signature (in that case accepting an HttpRequest
), but have no good way of expressing that so far in our type system or through language features.
Basically, a solution to this would be
typedef CloudFunction = void Function(HttpRequest);
void foo(HttpRequest request) implements CloudFunction {
...
}
As this is probably quite complex, a smaller step or help would be to add a signature to TargetKind
, as proposed in https://dart-review.googlesource.com/c/sdk/+/442740.
This is not as good, as it only shows what is going wrong, not providing much info as to what would be right as class interfaces do with giving users a quick fix to add missing methods, but would still be better than failing at runtime.
cc @srawlins