Skip to content

Function signature interface #4492

@mosuem

Description

@mosuem

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions