-
-
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
TS/flow typings? #254
Comments
I'm very interested to see this. It's not something I plan to work on at this stage as I'm focused on the existing modules ( |
Edit: some complications have been listed out by Isiah Meadows here:
|
Oh, that's unfortunate. I was quite excited about this library. Sadly, without (even bad) TS typings I cannot use it (employer won't pay me for writing typings). 😢 |
@mnn, I bet others would contribute if you were to start writing the TypeScript type definitions. 😄 |
Well, I am pretty sure I am not an ideal candidate - started learning TypeScript very recently and my knowledge of Sanctuary is limited to a brief browsing of your docs. 😑 But I'll try! 😄 Started working on it over there - https://github.com/mnn/typings-sanctuary. |
That looks like a good start, @mnn! |
This is promising, but given that TS support seems to be bleeding edge right now, i'm curious how others are dealing with this in projects? Are you simply using sanctuary's runtime type checks as an alternative to TS/flow? |
I imagine the alternative to compile-time guarantees has largely been On Thu, Nov 17, 2016 at 3:43 AM, Jonah notifications@github.com wrote:
|
I have only used Sanctuary in vanilla JavaScript projects. My experience is consistent with your imaginings, @tycho01: the combination of run-time type checking and unit tests catches many type errors. |
@jonahx TS support is definitely not ready, in current state I don't recommend using it for anything serious (there is not merged major change). But I am nearing finish line, I hope next week I'll be able to complete it. It won't be perfect, because (I think) some types are just not possible to capture by TS type system (like TypeRep and |
I'm pleased to hear you've been making good progress, @mnn. :) By the way, |
After many not working attempts I ended up with this create/module prototype (type in first case is not required). It's not ideal, but I can't think of any way how to improve it. I hope next week I'll update real typings according to this scheme and finish
|
Whoa :), might it be possible to publish on npm @mnn? |
After the update I'll look into it (never done it before, but from the link you posted it seems relatively easy). Another possibility would be to include the typings in the Sanctuary repository (that's the preferred way, but not always possible - not every JS library wants TS typings bundled). IIRC there were some issues with versioning when publishing standalone typings. Bundled typings work out-of-box and are always for the right version because the typings and the library are distributed together. Downside is a slightly larger library package (not resulting JS, only package), but only by a few kilobytes (in our case I guess like 30KB). |
I'm certainly open to this possibility, but I'll need to learn about the pros and cons. It also strikes me as a good idea to have people use your package for a couple of months, @mnn, before potentially opening a pull request to add the typings to the Sanctuary repository. |
Hi all, I wrote a first draft of the definition file for Flow, you can find it here. Contributions, tests and PRs are warmly welcomed. |
Very cool, @gcanti! |
As a side note, @davidchambers and all the contributors, thanks for the awesome documentation, I know is a tremendous effort. Precise signatures and many examples are very helpful when you write a definition file. |
@mnn: would you mind commenting on the script you used for the |
@tycho01 It's available at the repo - https://github.com/mnn/typings-sanctuary/blob/8f05ba2f87c3fa1de9462e7fb4e788b5610f6266/scripts/Pipe.hs. I am still learning Haskell, so the code is probably far from ideal. It surely could have been written in something like JS or Ruby, but I wanted to finally use Haskell for something real and useful, not just for exercises 😄. Or do you mean describing how it works (sorry, English is not my native language)? |
@mnn That's fine, was just curious. Thanks. :D |
@mnn my attempt in Ramda in the meanwhile: letters = (idx) => (n) => R.range(idx, idx + R.clamp(0, 26, n)).map(i => String.fromCharCode(i))
upper = letters(65)
lower = letters(97)
[lows, ups] = [lower, upper].map(f => f(25));
zipped = R.zip(lows, ups);
`export function pipe<${ups.join(', ')}, Z>(functions: [(a: A)=>${zipped.splice(1).map(([low, up]) => `${up}, (${low}: ${up})=>`).join('')}Z]): (a: A)=>Z;`
// export function pipe<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z>(functions: [(a: A)=>B, (b: B)=>C, (c: C)=>D, (d: D)=>E, (e: E)=>F, (f: F)=>G, (g: G)=>H, (h: H)=>I, (i: I)=>J, (j: J)=>K, (k: K)=>L, (l: L)=>M, (m: M)=>N, (n: N)=>O, (o: O)=>P, (p: P)=>Q, (q: Q)=>R, (r: R)=>S, (s: S)=>T, (t: T)=>U, (u: U)=>V, (v: V)=>W, (w: W)=>X, (x: X)=>Y, (y: Y)=>Z]): (a: A)=>Z; I've done a terrible job at switching to Haskell so far :P, being in front-end really isn't helping... |
I think you can also use numbers (with letters) for type variables |
@safareli: Yeah, that does appear to be method currently using in the |
@mnn Hi, do you have any success with the typings? Maybe you could push them to npm |
@mnn I've created an empty repo at https://github.com/types/npm-sanctuary now. I think @blakeembrey could provide you with direct push access. |
For older version types are for almost everything, but because of limitations of definitely-typed import script it can't be published there. Types for newer version are currently not really being worked on. (I started in my free time, but I am not sure if/when I finish it; I am only using TS+Ramda+Sanctuary at work and they don't seem to agree to pay for updating typings. Last time it took me several work days to type most of Sanctuary, also this time there is much more type-class things which will be difficult or even not-typable b/c of TS limitations.) If you want better solution than local package you could try |
Thanks, awesome work guys btw! @mnn I tried both pointing to github repo and localpackage, none of them worked. But I'm sure I did something wrong, I'll try again.
Latest TS versions (>= 2.2) bring significant improvements to typing, maybe it could help. |
At work we are using the local package way (not only for Sanctuary) and it's working alright. Make sure that
TS recently released 2.4, it should improve inference with generics (I haven't tested it, but it would be great if |
@mnn:
I'm not sure if 2.4 will help you much over 2.2 for inference by the way. Generic degeneration is still there. |
Thanks for the answer! |
I'm not sure who you were asking. I don't think it was me. Please correct me if I'm wrong. :) |
Guys you all are doing awesome work! All your opinions would be great :) I'm really impressed with sanctuary and especially how it is aligned with haskell. But I'm trying to find a Long-Term-Service solution... EDIT: (In terms of TypeScript) |
I'm not a TypeScript user. I don't know whether Sanctuary is a good choice for a TypeScript project. I understand that depending on Sanctuary in a TypeScript project is currently somewhat risky as it necessitates an additional dependency on a separately maintained typings package. If Sanctuary is to work with TypeScript at all we should eventually provide the typings directly, so TypeScript users would always have access to the same Sanctuary versions as JavaScript users. |
@raveclassic: one consideration there may be inference quality. I haven't used either much though it should be easy to try a That said, you may also consider current differences in focus. If Sanctuary is still more focused on run-time checks, that may add extra value if you are to check data coming in over the wire from APIs (alternatives there being e.g. JSON Schema). There seem to be other differences as well, with FP-TS focusing on ADTs while Sanctuary patches some basic functions, offering e.g. a safe I've personally found myself not using ADTs much yet in JS/TS -- I'm currently feeling somewhat excited about further trying partial.lenses as the next step from Ramda that also kinda seems to take care of safety. That said, not much progress with TS over there so far -- even in Ramda type inference for |
My two cents: Previous version of Sanctuary was typed for most part, sadly typings never made it to the official repo. Not sure in current version will be/would be something different... Also it seems really wild and not supporting previous releases. Current version removed dozens of methods (essentially breaking majority of code interacting with Sanctuary in our codebase), so if I ever update I would have to either update all occurrences with a new static variant (probably won't happen, because TS in this case has much worse type inference than with methods) or write wrappers for all removed methods (sounds very tedious, not sure if it can be automated). I would like to see something like what e.g. Angular does - they still support older version and propagate important fixes back. In case of Sanctuary it's crashing on circular data structures which forced me to disable runtime checks in dev build (without this Sanctuary is not that different compared to other libraries). Because of these issues I am no longer so sure about choosing Sanctuary for our project at work. Sanctuary has quite a lot of people using it (compared to TS variants), but usage from TS is not great in quite a lot of cases (e.g. mentioned Since it seems that I won't be working on the typings (other folks doesn't seem to contribute much, IIRC I had like 2 PRs with minor fixes; maybe at the end of summer I might get to it, but it depends on my employer), I can't recommend new TypeScript projects to use Sanctuary. If you are really considering using it, try using it first in some test project - e.g. in previous S version I was missing several things like something like bimap and I really hated having to specify type parameters in pipe when creating function from it (TS doesn't infer type parameters from usage [so we have literally full lines of type parameters for pipe calls], or at least in previous version it didn't). |
Just a clarification, fp-ts is not (and won't be) fantasy-land compliant (is just inspired by) |
Thanks for your answers! Will try to figure out which way fits best for the team. |
Hi everyone. Just started using Sanctuary - really nice work. I use VSCode as my IDE and this issue is resulting in me losing intellisense on all my Sanctuary-based functions. It appears that this issue was mostly solved at one point by @gcanti's libdef but then the library underwent a dramatic change and that libdef became obsolete. Since then, there's been no updated libdef. Am I understanding this correctly? Does anyone have even a partial solution to this issue that's compatible with the current version of Sanctuary? Thanks |
I'm working on TypeScript type definitions for inclusion in an upcoming release. Have a look at master...davidchambers/typescript if you're interested in seeing my progress. |
Looks like someone converted! :) It looks pretty good overall. I haven't tried them, but lemme try and list the little bits of feedback I can think of:
Honestly it looks pretty solid as-is already though, and I'll concede that type-level type-classes are not really within my experience. |
Looks like you need some tools to test types:
|
Is there any progress on this? |
Despite significant effort, I have not succeeded in making Sanctuary and TypeScript play nicely together. I use TypeScript at work, with fp-ts. TypeScript provides a lot of value to the team, despite its many imperfections. fp-ts is a fantastic library; I highly recommend it. The only thing that frustrates me is TypeScript's naive type inference, which sometimes forces me to redundantly specify a type or to replace I am motivated to make Sanctuary an even better library for functional programming in JavaScript. To those using TypeScript, I recommend trying fp-ts. :) |
@davidchambers Thanks for this helpful, clear, and quick reply! |
Gitter:
I was thinking it might be useful to put this out here, so we could consolidate questions/issues and perhaps check for solutions with the TS/flow team.
Potentially relevant (TS):
The text was updated successfully, but these errors were encountered: