You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Types in TS are getting increasingly complex, as the compiler supports more advanced features and the community gets more comfortable with fancy types. In some cases, though, the defintion for a type can have a lot of duplication in it, of reused type expressions. This can make the type hard to understand, and pulling out the duplicate bits into helper types may add indirection that isn't worth it/also makes things hard to follow. The duplication can also make the type more cumbersome to update/refactor.
Therefore, this feature request would be to have some way to name an intermediate type when defining a type, analogous to let Binding [, Binding ...] in Expression-style expressions in Haskell, Lisp, etc.
My proposed syntax is with type Type [, Type ...] return Type, but that can be bikeshed as needed.
Here's an example, using a type I was writing today. The details don't matter, except that it's large and full of duplication:
The text was updated successfully, but these errors were encountered:
ethanresnick
changed the title
Haskell-style let expression for defining complex types
Type-level let expressions for defining complex types
Jun 16, 2023
Suggestion
💻 Use Cases + Motivating Example
Types in TS are getting increasingly complex, as the compiler supports more advanced features and the community gets more comfortable with fancy types. In some cases, though, the defintion for a type can have a lot of duplication in it, of reused type expressions. This can make the type hard to understand, and pulling out the duplicate bits into helper types may add indirection that isn't worth it/also makes things hard to follow. The duplication can also make the type more cumbersome to update/refactor.
Therefore, this feature request would be to have some way to name an intermediate type when defining a type, analogous to
let Binding [, Binding ...] in Expression
-style expressions in Haskell, Lisp, etc.My proposed syntax is
with type Type [, Type ...] return Type
, but that can be bikeshed as needed.Here's an example, using a type I was writing today. The details don't matter, except that it's large and full of duplication:
Syntax today
Proposed syntax
As you can see, the new syntax not only makes the type much shorter, it also makes it much easier to read and understand.
🔍 Search Terms
temporary type alias let expression types
✅ Viability Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: