-
-
Notifications
You must be signed in to change notification settings - Fork 95
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 Maybe<A> #649
Comments
I recall being unable to export the |
What is the difference with |
Haskell has polymorphic literals: Prelude> 1 :: Int
1
Prelude> 1 :: Float
1.0 Haskell also has polymorphic functions: Prelude> pure 1 :: [Int]
[1]
Prelude> pure 1 :: Maybe Int
Just 1 Note that the type of JavaScript has no type inference, so a function like > S.of
of :: Applicative f => TypeRep (f a) -> a -> f a
> S.of (Array) (1)
[1]
> S.of (S.Maybe) (1)
Just (1)
|
I see the difference now, thank you 😊 . What about doing something like declare module 'sanctuary' {
interface Maybe<A> extends IOrd<Maybe<A>> {
constructor: MaybeTypeRep
}
interface MaybeTypeRep extends TypeRep {
'@@type': 'sanctuary-maybe/Maybe@1';
'fantasy-land/of'<A>(x: A): Maybe<A>;
}
var Maybe: MaybeTypeRep;
} import { Maybe } from "sanctuary";
S.of(Maybe) (1)
type someMaybe = Maybe<number> with this typescript is able to tell when we're using the type |
The solution proposed in your edited comment sounds ideal, @edgarjrg! Could you submit the change to vicrac/DefinitelyTyped? That would get us significantly closer to releasing new type definitions. :) |
The only problem I see is: exports=S With the previous propose we need to change from custom single object to ambien module , and export each function from declare module "sanctuary" {
export function of<A>(x: A) ...
export interface SanctuaryStatic {
of: typeof of
}
} Other solution would be /// <reference path="Maybe.d.ts">
exports=S That would make I incline for the ambient module, but the reference path/types are valid, especially is the type of maybe lived in |
@edgarjrg Can you explain your solution a little bit more? |
@mohsensaremi I had success with these changes to the I really just had a a couple of hours experimenting with the library and used an absolute minimum of features, so I don't know, if it works well enough or breaks somewhere. Maybe (pun intended :) someone else more experienced with sanctuary-js have a look over it. If you want to test it, just copy paste the content in |
Hi ! @davidchambers @vicrac and I worked in this improvements in order to make available the types of maybe and others through ambient modules, we never finished the work, but would be nice to. |
@mohsensaremi the types we're trying to make are based on this spec: https://github.com/fantasyland/fantasy-land , The point is that Sanctuary works with this algebras, so functions can be more composable, if I say that That's why for My solution had to do a bit more with how the type module of Sanctuary is build, with the current way it is impossible to export |
This is the roadmap to finish the types, currently the PR that @vicrac open is closed by now, and I didn't had more time then to continue, but it would be nice to finish. |
@edgarjrg Can I use this fork https://github.com/vicrac/DefinitelyTyped/blob/master/types/sanctuary/index.d.ts now? |
You could, not all functions are typed, but it should be compatible with everything, it’s just typings. |
@edgarjrg
These statements should throw error but the code is compiled successfully. |
@mohsensaremi i'm looking into it. It looks like some kind of TypeScript soundness issue about generics, might be related to https://github.com/Microsoft/TypeScript/wiki/FAQ#why-is-astring-assignable-to-anumber-for-interface-at-- . |
@edgarjrg |
@mohsensaremi you can try now from this commit I added your use cases as tests and improved a bit the types. This is not a done job at all, the library however works perfectly ignoring TypeScript if you just want to do that, the runtime checks of Sanctuary are far more advanced and safe than TypeScript at this point. You can also try https://github.com/gcanti/fp-ts/ I found those types more robust for TypeScript, but there's no actual runtime garantes like the ones provided by Sanctuary. And for the record i'm just a regular person that's trying to help this great project with nothing in return like everybody else, it's frown upon to ask for quick fixes, but no worries, I know you say that with the best intent in mind ✌️ |
I second the fp-ts recommendation (for TypeScript projects). 👍 |
Hi! Incredible library 👏 thank you 🙏
I'm using Sanctuary with Typescript (@types/[email protected]) and the type of S.Maybe is not exported, i copied the type and use it in my own folder and worked but the type itself is not very useful basically everything matches with it.
Is there any alternative for the typing of Maybe ? or any way i could contribute?
Thank you in advance 🙏
The text was updated successfully, but these errors were encountered: