-
Notifications
You must be signed in to change notification settings - Fork 102
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
typescript typings #65
Comments
Unlikely for now, the type system implemented by TypeScript (and Flow) are not expressive enough to support most of the constructs that Folktale uses, so you'd just end up with a lot of Depending on how Flow and TypeScript advance in the future I might look into this again, though. Right now Folktale requires at the very least three type system features:
Some features use reflection or generate values. These could only be typed if we had a type system with dependent types (that is, your types are basically functions, so you can write things like |
Thanks for a great answer @robotlolita , I’ve been wondering the same thing as @djleonskennedy for a while, it’s good to have a complete explanation about this. |
Understood thank you @robotlolita |
Also have addition, even |
I agree with @djleonskennedy |
@djleonskennedy doesn't TypeScript infer |
@robotlolita if |
Mmh, I'll look into this over the weekend. |
@robotlolita thank you |
It's fine to use with typescript I'm just applying a band aid fix for now by declaring the module with
|
@piq9117 thank you i use it now in this way |
I hacked together some typings for use with the declare module 'data.maybe' {
import Validation from 'data.validation';
const Maybe: {
fromValidation: <Success, Failure>(validation: Validation<Success, Failure>) => Maybe<Success>
fromNullable: <T>(nullable: T | undefined | null) => Maybe<T>
Just: <T>(t: T) => Maybe<T>
of: <T>(t: T) => Maybe<T>
Nothing: () => Maybe<never>
}
type Maybe<T> = {
value: T
getOrElse: (fallback: T) => T
map: <T2>(fn: (t: T) => T2) => Maybe<T2>
chain: <T2>(fn: (t: T) => Maybe<T2>) => Maybe<T2>
}
export default Maybe
}
// Applicative
declare module 'data.validation' {
const Validation: {
Success: <Success>(success: Success) => Validation<Success, never>
of: <Success>(success: Success) => Validation<Success, never>
Failure: <Failure>(failure: Failure) => Validation<never, Failure>
}
type Validation<Success, Failure> = {
getOrElse: (fallback: Success) => Success
map: <Success2>(fn: (success: Success) => Success2) => Validation<Success2, Failure>
ap: (validation: Validation<any, any>) => Validation<any, any>
cata: <T>(obj: {
Success: (success: Success) => T,
Failure: (failure: Failure) => T
}) => T
}
export default Validation
} I'm very much making it up as a go along. I've had to type |
Also, looking around for a good FP library with support for TypeScript and Fantasy Land, I don't think there's any really strong contenders at the moment. I would love to see Folktale emerge and fill this niche :-) |
@OliverJAsh With microsoft/TypeScript#6739 you can probably write:
But I haven't tried it yet. I don't know if it's on the current TS version either. |
Oh, wow! Thanks @robotlolita |
@robotlolita That change is included in TS 2.3 which is currently out as a release candidate (RC): https://github.com/Microsoft/TypeScript/releases/tag/v2.3.0 |
@OliverJAsh check out https://github.com/gcanti/fp-ts for ADT in TypeScript if you haven't already – the project seem to be moving fast. |
Hello
Is there in plans to add typescript bindings to "folktale" ?
The text was updated successfully, but these errors were encountered: