typescriptlivescriptprelude.ls

How to use module prelude-ls in TypeScript


I program in LiveScript and use the external module prelude-ls to do things as chaining, mapping, folding, grep or other functional concepts.

In LiveScript, I can do

_ = require 'prelude-ls'
[1 2 3] |> map (*2) |> filter (> 4) |> fold (+)

But if I do, in TypeScript

import _ = require('prelude-ls');

I receive the following error:

# => Cannot find external module 'prelude-ls'

But I have this module installed and I use it with LiveScript. Is there any way or any similar library to use within TypeScript?


Solution

  • This isn't because the prelude-ls module doesn't exist - it is because TypeScript doesn't have information about it.

    I have checked and I can't find an already-made definition file - but you can start by creating a file named prelude-ls.d.ts and adding the features you use.

    For example...

    declare module PreludeLS {
        export function map<T>(func: (item: T) => T, data: T[]) : void;
    }
    
    export = PreludeLS;
    

    Which would allow you to use the map function:

    import _ = require('prelude-ls');
    
    _.map(function (x: number) { return x + 2; }, [1, 2, 3]);
    
    _.map(function (x: string) { return x + '__' }, ['A', 'B', 'C']);