Replies: 1 comment
-
In general, using a contract as a type is very restricted. As contract may be arbitrary predicates, the only way the typechecker accepts that something is of type Current solutionsAdding a contract annotationIn your example, that would means:
This is a bit sad, because:
Relax the type annotationAnother solution is to trade the static annotation of Future solutions (requiring additions to Nickel)Type aliasesOne possible future solution would be to support type aliases indeed, and to make Associating static type to contract (+ type aliases)A second possible future solution, in addition to type aliases, is that the typechecker is smart enough to derive that some contracts (mostly record contracts) are equivalent to a static type. This is discussed as future possible evolution in RFC002. Your initial example would just work without modification. In any case, if you feel this is current limitation, opening an issue to keep track of user requests is very welcome 🙂 |
Beta Was this translation helpful? Give feedback.
-
Example:
Calling the above function produces:
Are we limited to using only static types in this case? Or am I expected to set the type to
{image: Str, name: Str, type: Str}
every time I want to ensure a "Builder" is getting passed into my function? Perhaps a better tool here would be a type alias, but it doesn't appear those are supported either.Beta Was this translation helpful? Give feedback.
All reactions