Constrained primitive types

Open
#38 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
backend

Research direction

This is a design discussion about a general mechanism for constrained primitive types, not a bounded change. Read the custom type API example at packages/typir/test/kinds/custom/custom-example-restricted.test.ts to see how restricted types are built today. The issue has no comments and no assignee, so any work would need the maintainers to agree on the API first. Done would mean a proposal agreed on in the thread, not a code patch.

Written by the indexing model from the issue text.

Description

New Feature Predefined Types

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 #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.
Dominant language
TypeScript
Stars
52
Forks
5
Avg merge
1h 31m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from TypeFox/typir

All issues in TypeFox/typir

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.