Skip to content

Allow struct types to typecheck optional/unknown fields #25

Description

@WillBAnders

Currently, structs use structural subtyping which considers any struct to be a subtype so long as the required fields are present. This is insufficient for handling optional/unknown fields, which is an important part of type safety when working with structs (particularly when involving default values).

  • Optional fields may be provided, but if so must typecheck successfully. It is unclear if there's an effective way to represent this with null such that users are not confused between required, nullable fields, optional, non-nullable fields (as with JSON). Maybe optional is handled differently for subtyping but accessing fields returns Nullable versions (properly wrapped for optional, nullable) ?
  • Unknown fields are generally a concern for type safety, but could be useful for abstractions involving structs (such as transforming specific fields but leaving all others untouched). There are currently no plans to do any kind of more customizable [key: string] clauses as with TypeScript, just a general "all other fields".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions