Skip to content

Consider typing interface{} fields? #20

@abustany

Description

@abustany

First of all, thanks for the work you're putting into this!

There are couple of places in the Go API where the type of a field is only known at runtime (eg. Page.Properties), so the field is typed as interface{} in Go. One approach that's used eg. by the protobuf runtime is to use an interface with a "dummy" method that uniquely identifies the implementors, which helps both IDEs/language servers to do autocompletion and the compiler to ensure that the code is correct.

A simple example

type Page struct {
   Properties IsPageProperties
}

type IsPageProperties interface { isPageProperties() }

type PageProperties struct { /* ... */ }

func (PageProperties) isPageProperties() {}

type DatabasePageProperties struct {  /* ... */  }

func (DatabasePageProperties) isPageProperties() {}

let me know if you think this approach makes sense, and I can try to send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions