hegel icon indicating copy to clipboard operation
hegel copied to clipboard

Generating type annotations for functions

Open jarble opened this issue 3 years ago • 4 comments

I want to generate some type annotations to a function like this one:

function abs_pow(a,b){
    return Math.abs(Math.pow(a,b));
}

With type annotations, it would look something like this (using TypeScript syntax):

function abs_pow(a:number,b:number):number{
    return Math.abs(Math.pow(a,b));
}

Is it possible to generate these annotations automatically using Hegel, instead of typing them manually?

jarble avatar Dec 04 '20 03:12 jarble

@jarble currently hagel will infer type (number, number) => number for that function so there is no need to write it manually

thecotne avatar Dec 04 '20 11:12 thecotne

There should be some way to generate annotated source code from a program without type annotations: the documentation doesn't explain how to do this, so I don't know if Hegel has this feature yet.

jarble avatar Dec 04 '20 15:12 jarble

you mean generating .d.ts files? i think that is not implemented yet

thecotne avatar Dec 04 '20 15:12 thecotne

Hi @jarble . Yes, we have a high level of type inference, so you able to skip an annotation of your arguments and return type. We described it in the section of the documentation. If you mean by "automatically generating of an annotation" a generating of d.ts file with annotation, then I want to say, that this part of the project currently in development. I'd a little bit stop working because I'd married :D But I promise I will come back to the project soon :3

JSMonk avatar Dec 05 '20 19:12 JSMonk