tjanczuk / edge

Run .NET and Node.js code in-process on Windows, MacOS, and Linux
http://tjanczuk.github.io/edge
Other
5.41k stars 641 forks source link

Typescript Typings #589

Closed atrauzzi closed 5 months ago

atrauzzi commented 7 years ago

Would love to see official TS typings for this library. Either as part of the package itself, or in the definitely typed repository! 😄

agracio commented 7 years ago

Edge is pretty much limited toedge.func( type of calls, not sure what typings you have in mind.

edge.func(function() {/*
    async (input) => {
        return (int)input + 7;
    }
*/});
atrauzzi commented 7 years ago

Would be useful if it accepted a generic parameter for the return and also described its parameter.

I know it seems small, but it's important and without the definition, anyone who doesn't allow implicit any has to do ugly things to make the library work.

rummelsworth commented 7 years ago

I wrote the following edge.d.ts file for my project:

declare module 'edge' {
  function func<TInput, TOutput>(params: string | Function | Params): Func<TInput, TOutput>
  interface Params {
    assemblyFile: string
    typeName?: string
    methodName?: string
  }
  interface Func<TInput, TOutput> {
    (payload: TInput, callback: (error: Error, result: TOutput) => void): void;
    (payload: TInput, sync: true): TOutput;
  }
}

I think that as long as this is sitting somewhere inside your TS project folder, tsc should pick it up.

@tjanczuk Would definitions like this be accepted if PR'd here? If not, maybe someone willing to take on the (probably minor) responsibility of maintaining the accuracy of these declarations could PR them to DT.

agracio commented 7 years ago

Its missing this implementation (https://github.com/tjanczuk/edge#how-to-specify-additional-clr-assembly-references-in-c-code):

edge.func({
    source: source // function(){} or path to .csx file,
    references: [ 'System.Data.dll' ] // external references
});

There haven't been any activity on this repo for a long time and @tjanczuk recently set a 'Hello World!' auto-reply for all new issues and none of the recent PRs including one of mine got merged. I maintain a fork at https://github.com/agracio/edge-js that has some PRs merged already and my own fixes to the code. Will be happy to add definitions to it as I am Typescript developer myself.

rummelsworth commented 7 years ago

Awesome, sounds good @agracio . Are you also publishing updates to the npm package?

agracio commented 7 years ago

Npm package is called edge-js, its up to date with the latest NodeJs security fixes. Add the missing definitions to your code and ill merge it.

agracio commented 6 years ago

New edge-js NPM package now includes Typescript definitions file.