neutralino.js
neutralino.js copied to clipboard
Typescript not being used to it's full potential
Hello,
Right now Neutralino is not using Typescript to it's full potential:
- First I would like to suggest a full reorganization to use more types instead of returning Promise< any > everywhere.
- Second I would make a available a typescript declaration file (.d.ts) for people using typescript in their apps.
This would make the API much easier to use without the need for always checking the docs and would reduce the amount of errors of calling the API functions wrong.
I wouldn't mind helping in both steps if you accept this suggestions. Keep up the good work!
Best regards!
Hello,
For the Promise, this is the principle of Neutralino. it's talking to a background server. It's a shame that all calls return the type Promise <any>
For the .d.ts file, I created mine, you can use https://gist.github.com/corbane/e67cecbd4726f84ca23c8e9b4cb7428d
What is also a shame is the use of Ts enumerations, If you try to do as in the starter project:
Neutralino.os.showMessageBox({ type: "INFO" ... })
(main.js#30), you may get type checking error.
hope it can be useful
Yeah agree @danisss9 and thanks for the https://github.com/neutralinojs/neutralino.js/pull/11 @corbane I will check and merge it soon. Regarding the Promise<any>
, yeah we need to return the exact fields return from the server. I think we can do it now because now https://github.com/neutralinojs/v2-client-specification is done. So we have a stable return value per each method.
@corbane yes i wanted to say the "any" was the "problem" not the promises but github removed the "< any >" part probably thiking it was a html tag xD
Hell @danisss9 , indeed we say the same thing :)
Hello @shalithasuranga
In this PR, I make sure to respect your build system (webpack) but I have a better result with rollup. I updated the Gist to an rollup version If you are ok with that, I can update the PR with Rollup ?
The advantage is that the generated files are cleaner and smaller. The disadvantage is that 'neutralino.js' is generated by a new tool and I don't have enough experience with Neutralino to test it.
I wanted to update the JSON types returned by the server, so I read the client specification v2 and the source code of Neutralinojs. about this, i really like your source code, it is clear. For this reason, I haven't found a solution to extract message schemas from C ++ sources without destroying the readability of your code. I think the spec should include JSON schemas, IDL or other, so that we can generate Ts definitions and unit tests.
There is also a package the Neutralino types called neutralinojs-types
. I have no idea if it is better than @corbane’s neutralino-1.5.0.d.ts
.
Update: It really would be a great idea to provide neutralino.js
with TS types. Also, I think you should consider publishing it on NPM it might simplify its usage.
Closing this since we have now a TypeScript-ready NPM package: https://www.npmjs.com/package/@neutralinojs/lib
Thanks all :)