mnn / typings-sanctuary

*UNMAINTAINED* type definitions (for TypeScript) for JavaScript library Sanctuary
12 stars 2 forks source link

Fix inference for generic in functor #14

Closed OliverJAsh closed 7 years ago

OliverJAsh commented 7 years ago

Without describing how the generic F is used in the interface, there's no way for TypeScript to perform inference when a functor is provided.

Example:

{
    const functor = {
        map: (fn: (x: string) => string) => functor
    }
    S.map(x => x.trim(), functor) // Property 'trim' does not exist on type '{}'.
}
OliverJAsh commented 7 years ago

Updated base to S_0.12 branch.

mnn commented 7 years ago

Sorry it took that long, but sadly I don't think I will be maintaining this typings anymore :confused:. (At work we are using a "methods" form, but that is being removed in new Sanctuary version. Function composition has issues with TypeScript [one has to manually specify a lot more types - inference is often not working], so using methods is, at this time, a much better choice. For now we are staying on the old version, but we will probably switch to something else [maybe I'll write something, we are not using that many things from Sanctuary], because only unique thing Sanctuary offers - dynamic type checking - is broken at that version).

davidchambers commented 7 years ago

@mnn, it would be quite easy to write a Sanctuary wrapper which modifies prototypes to support method chaining. For example:

const S = require('sanctuary');

S.Maybe.prototype.map = S.Maybe.prototype['fantasy-land/map'];
...

module.exports = S;
OliverJAsh commented 7 years ago

You should check out fp-ts https://github.com/gcanti/fp-ts