Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant Value Types #133

Open
sezna opened this issue Jul 27, 2024 · 0 comments
Open

Constant Value Types #133

sezna opened this issue Jul 27, 2024 · 0 comments

Comments

@sezna
Copy link
Collaborator

sezna commented Jul 27, 2024

Literals should be allowed as types, and they will be subtypes, processed via the Satisfies constraint, of their parent types. For example,

type Foo = '"this" | '"that"; -- the ' denotes that it is a type, and not a value.

Then, fn foo(foo in 'Foo) could only ever accept "this" or "that". But fn foo(foo in 'string) could accept a 'Foo, or any other string.

This is more ergonomic than having to define an enum with to_str() and from_str() like Rust, and is one of the more valuable features from the Typescript type system that I enjoy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant