Skip to content

Constrained primitive types #38

@JohannesMeierSE

Description

@JohannesMeierSE

Examples are:

  • strings with restricted length, regular expressions (type inference for concatenation of restricted strings)
  • min/max / ranges for numbers (type inference for addition of ranges: <range> + <range>)
  • physical units
  • arrays with fixed length

Requirements:

  • Assignability/sub-type rules depend on the current DSL!
  • Provide general mechanism / API for "arbitrary" constrainted primitives
  • Maybe provide some defaults?
  • Maybe support additional properties (not generics Generics #26!) for types, which are not relevant for assignability/validation, but for code generation, e.g. UTF-8 encoding for strings?
  • Default behaviour of new parameters is empty, add more behaviour if required by explicit API calls for e.g. assignability, inference
  • Maybe these issues target not only primitive types, but any kinds of types?

Ideas for solution

  • It is possible to realize constrained primitive types with the custom type API, see: packages/typir/test/kinds/custom/custom-example-restricted.test.ts, but maybe there is an easier way.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions