Open Raynos opened 10 years ago
As we consider each of these features, could you attach a use-case that they solve?
\
allows you to specify a type that is a union with things.
For example the divide : (top: Number, bottom: Number \ 0) => Number
function.
This is the inverse of |
and is useful when thinking of types as sets.
Other languages allow you to create generics with constraints (see C# and typescript).
For example an extend function might be xtend : ( T <: Object, S <: Object) => T & S
.
By default in generics when we say type Promise<T> : { ... }
we actually mean type Promise<T <: Any> : { ... }
This is one is complicated, will need a seperate issue to discuss.
This allows you to say Object<Pattern<"\d+">, T>
i.e. I take an object where the keys are numeric and the value is a T
. I'm not sure whether we want this as a first class thing.
We can already define type Pattern<T> : String
and then have a smart validator take the Pattern
meta data and do smart validation where as the full type checker will just resolve the above object to Object<String, T>
Instead of doing a generic as type MyGeneric<A, B> : { ... }
and then doing foo : (MyGeneric<A, B>)
we might want to use destructuring instead.
i.e. type MyGeneric<{ a: A, b: B }> : { ... }
and then do foo : (MyGeneric<{ a: A, b: B }>)
This is only really useful for building a "DSL" in the custom generics you define in JSig. One use case is the type Range<{ lt: A, gt: B, gte: C, lte: D }> : Number
dsl which will resolve to Number
checking in the type checker but a smart validator / runtime checker might interpret it as a range restriction on numbers.
I opened an issue for closed vs open #45
This issue is a set of bullet points for extra ideas in my head
\
e.g.type T : Number \ NaN
<:
e.g.foo : (T <: Object) => T
...:
e.g.foo : { a: Number, ...: T }
Pattern<>
e.g.type schemas : Object<Pattern<"\d\.\d\.\d">, T>
type Range<{ gt: T <: Number, lt: S <: Number }> : Number
cc @Matt-Esch