Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better typescript type support #175

Open
2234839 opened this issue Mar 18, 2024 · 11 comments
Open

Better typescript type support #175

2234839 opened this issue Mar 18, 2024 · 11 comments

Comments

@2234839
Copy link

2234839 commented Mar 18, 2024

I'm a newbie to esprunio and the official documentation [https://www.espruino.com/Typescript+and+Visual+Studio+Code+IDE](https://www.espruino.com/Typescript+ and+Visual+Studio+Code+IDE) which seems to be aged and actually difficult to run.

The library @types/espruino also doesn't type-define as expected, so I also need to write a .d.ts file for more accurate type-definition when using typescript.
https://github.com/2234839/espruino_ts

I remember seeing an issue about espruino automatically generating type definitions, and I'd like to handwrite a better @types/espruino for esprunio if this converter doesn't live up to expectations.

Is this required, and if so what are the other requirements?

@gfwilliams
Copy link
Member

Hi,

Thanks - yes, the documentation for TypeScript on Espruino isn't great

@bobrippling when you have a moment, would you be able to jump in and provide some pointers? @bobrippling has done a huge chunk of Typescript work, especially for Bangle.js, and I believe most of that is now auto-generated: https://github.com/espruino/BangleApps/tree/master/typescript

@bobrippling
Copy link

Hey - yes I'm not familiar with @types/espruino but I'd be happy to take a look over PRs to update it if that's what you're thinking? Let's go through the problems you found when trying to run it too, we can see what we can improve there.

How have you found setting up the repo you referenced?

@gfwilliams
Copy link
Member

Actually I realise the directory I linked also links to https://github.com/espruino/Espruino/blob/master/TYPESCRIPT.md which explains about auto-generating the typescript - a lot of work has gone into that, so if we can find any way to not hand-write TS declarations that would be way better.

I feel like probably we need a generic (non-bangle.js) export and to then try and get @types/espruino updated, ideally with some instructions in there pointing back to https://github.com/espruino/Espruino/blob/master/TYPESCRIPT.md to that folks in future know how to update it

@2234839
Copy link
Author

2234839 commented Mar 20, 2024

I tried updating scripts/build_types.js so that the espruino.d.ts it generates matches the type definitions (http://www.espruino.com/Reference#software) in the official api documentation

@bobrippling
Copy link

Cool, do you have the branch for this?

@2234839
Copy link
Author

2234839 commented Mar 21, 2024

Cool, do you have the branch for this?

I am reading through the code;
I find that scripts/build_types.js generates much better type files than the npm lib @types/espruino, so why hasn't @types/espruino been updated.
In addition, I can see that some of the type definitions could be optimized, for example, function getDetails(callback?: any): any; The callback here could be better defined, so that the user knows the type of the callback function's arguments.

@gfwilliams
Copy link
Member

so why hasn't @types/espruino been updated.

That's a good question - maybe you could submit a PR to the project?

I can see that some of the type definitions could be optimized

If you see something you want changing you are welcome to contribute updated typings. If you find the relevant file (which you can do by going to https://www.espruino.com/Reference#software, finding the function and clicking => in the title) you can add typescript as mentioned in https://github.com/espruino/Espruino/blob/master/TYPESCRIPT.md to improve the automatic generation.

@2234839
Copy link
Author

2234839 commented Mar 25, 2024

I'm writing a simple type inference script, and during debugging I realized that
JsVar *jswrap_wifi_getDetails(JsVar *jsCallback) {{ Is the {{ here a clerical error, when in fact only a { is needed (This is inferred from my experience with js.)

图片

@gfwilliams
Copy link
Member

I don't see any `{{ in that screenshot? But that file is C, not JS

@2234839
Copy link
Author

2234839 commented Mar 25, 2024

I don't see any `{{ in that screenshot? But that file is C, not JS

https://github.com/espruino/Espruino/blob/62546cca3a8cebeee7ccb6fd7a4a89d2b973e61d/libs/network/esp8266/jswrap_esp8266_network.c#L742C1-L742C52

The end of this line

gfwilliams added a commit to espruino/Espruino that referenced this issue Mar 25, 2024
@gfwilliams
Copy link
Member

Ahh, sorry - didn't spot that! Yes, that's a typo. It won't affect the code, but it's a bit ugly for sure - just fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants