hegel icon indicating copy to clipboard operation
hegel copied to clipboard

Porting TypeScript's 'declare const' to Hegel

Open adkelley opened this issue 5 years ago • 2 comments

Thank you for developing Hegel. I've been looking for a typed FP in JavaScript, and I think Hegel fits the bill.

One issue, however, is that I'm looking to migrate global variables, objects, functions, etc. over to Hegel. For example, the following in TypeScript allows me to extend the NodeJS global namespace object:

`import { doGet } from './do-get';

declare const global: { [x: string]: any; };

global.doGet = function (e: any) { return doGet(e); };`

adkelley avatar Jul 18 '20 21:07 adkelley

facts:

  • hegel does not have any (you should not need any in typed language)
  • hegel does not allow declare inside js file (i think it would be better to allow this)
  • hegel does not have indexer properties (there are some attempts currently but it does not really work yet #238 #144)

what you can do is to declare globals in .d.ts file and if needed ignore line where you are assigning to global variable with @hegel-issue

thecotne avatar Jul 19 '20 18:07 thecotne

@thecotne, Thank you a lot for your answer. Want to add one remark, that Hegel support indexer properties inside d.ts files.

JSMonk avatar Jul 19 '20 22:07 JSMonk