Interpreter
Interpreter copied to clipboard
Allow struct types to typecheck optional/unknown fields
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
nullsuch that users are not confused betweenrequired, nullablefields,optional, non-nullablefields (as with JSON). Maybe optional is handled differently for subtyping but accessing fields returnsNullableversions (properly wrapped foroptional, 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".