Typescript and BangleJS

Posted on
  • How vibrant is the Typescript + Espruino community? I see a "getting started" and a type definition for Espruino but it is fairly outdated. Attempting to update the repo gets stuck in use of the var global property in Espruino's type definition. I believe it conflicts with Node's own Type definitions.

    I am planning to hack together something to get TypeScript and BangleJS working. If more people are interested I will try to be clean enough to be able to push it to DefinitelyTyped repository.

    Cheers.

  • I'm a recent convert to TS and would love to have pre-built type definitions for Espruino (I found that most of the issues that come with porting legacy apps to TS is the lack of typedefs and therefore wrestling with TS to just get things done).

  • @parasquid I am an Espruino noob, so I can't speak for the type definition referred to in this post -> https://www.espruino.com/Typescript+and+Visual+Studio+Code+IDE

    I have a fork of the quickstart here but I still haven't managed to get all bits running without errors. Atleast it has all dependencies upgraded and latest version of Gulp.

    I am not going to mess up the Espruino type definition in DefinitelyTyped unless someone files a bug for it. But you probably need to dig into the node_modules\@types\espruino\index.d.ts and comment out line number 3692 that says declare var global: any; The variable 'global' conflicts with another one in node.d.ts I believe.
    I think I'll start a self contained repository for the BangleJS typedef and slowly get familiar with Espruino myself. I'll post updates here.

    Cheers.

  • Regarding this global: may be some other ways of implementation could help. Node is JS but it is not the birth place of JS. It was the browser, and in the browser there is an implicit 'global'... where all the things 'hang of', similar as in Smalltalk, where #Smalltalk is the global.

    In a microcontroller context where resources are extremely scarce, some (software) technologies / techniques used in other contexts are not that overall beneficial. On the other hand - if developed in a simulation environment / cross-developed and then 'broken'/converted/transpiled down for the 'little cousin runtime environment - why not to use. Unfortunately, these transpilers & cie. are machines and deliver results not that easy for humans to consume... yes, I know, this already starts with source code maps... but for Espruino, they already cost the runtime code byte(s) for each of the functions.

  • Vanilla javascript should work in Typescript as well, although it can help to prevent some bugs. I like the clean one on one IDE. If you work in Typescript, you'll have to build/compile it to javascript before uploading it to an Espruino device.

    Maybe typescript uses a lot of polyfills, which would make the code bigger than vanilla javascript. Although Typescript can have its benefits. I'll doubt if it will be better for use in Espruino.

    I'm working on a StencilJS PWA-application, which works in Typescript, just like many other front-end applications. I started to convert https://www.puck-js.com/puck.js to a typescript module, but it's a bit tricky.

    For now, I have put it in index.html and 'imported' window.Puck to use the Bluetooth connectivity.

    Regards, Peter

  • @Dutch_Peter

    ...it can help to prevent some bugs.

    And it does - like any other well typed language. It prevents from simple typos getting the better of the code. Nice in many IDEs and linters are that they indicate undefined / uninitialized references and help to get these issues as well.

  • @Dutch_Peter whatever works. This thread is for bringing forward experiences/issues using Typescript to develop BangleJS apps in particular which can be expanded to Espruino in general.

    I am halfway through Type definition of Bangle API. Still wondering if I should takeup the challenge of updating the entire Espruino type definition. It is a bit of Yak shaving I rather not get stuck in. I want to have a Bangle JS App ready rather quickly.

    The TS quickstart project I referred to (above) has a lot of Espruino specific steps that actually sets you up well for Espruino devices. I'll try and adapt it to Bangle as far as possible.

    I am not rewriting anything in Typescript, rather I am just creating Type definitions for existing APIs to help use TS to write Espruino code.

    I am pretty sure the TS compiler/transpiler generates better JS code than I can hope to write. For those who can write better JS code directly, rock on folks!

  • @PiOfThings (@Dutch_Peter), did you consider to integrate the type description w/ the sources and let the generation/ pub of the site - in particular the reference and (minified) modules generate / pub it at the same time? ...this way it could be kept in sync much easier?

  • I am halfway through Type definition of Bangle API

    I can't remember for sure, but I think the initial definition may have been made with a script? There should be a decent amount of info in the Espruino codebase (those /*JSON comments in the code) to help, and if it's not detailed enough we could look at improving that, so we have a way of always creating typescript decls that are up to date.

    https://github.com/espruino/Espruino/blob/master/scripts/build_jsstub.py is a simple example, but there's actually much more type info in there

  • @Gordon that is a nice trick. It seems Typescript now has the ability to generate TypeDefinition stubs from JsDocs... I'll give it a go and update here.

    My progress has been slowed down due to other hobby distractions, please bear with me :-)

  • Imo the current @types/espruino under DefinitelyTyped is incomplete. eg. there's no definition for the Storage module.
    I've found this other one in this Github repository but have no idea where this came form, seems to be generated as well. Can't reach the owner.

    I've just finished porting my existing NodeMCU + Lua code to Espruino + Typescript, and it worked quiet well. Although one needs to be careful, because even though you can target ES6, some features are missing. eg. initially I was using the Map structure to handle some things, but that was not working and went back to basic JS dictionaries (where Typescript can still gives a bunch of type hints fortunately).

    I wonder what other people use for transpiling and minification. I'm using Rollup + Uglify right now, but maybe Babel would do more and polyfill some missing stuff and make it a more transparent experience. I don't know if it's possible to define a more specific set of supported ECMAScript features for a transpiler; an up-to-date Espruino fitting profile could be done that way.

    (Also I would love to play with this watch, but I was too late for the Kickstarter party, and it's kind of expensive now. :( Got me thinking if there are other open source watches available, and interestingly the PineTime seems to use a very similar hardware; I wonder if the manufacturer behind is the same or not.)

  • Keep on working on typescript :)

    WRT the Pinetime: it ships with a locked firmware, so you can't change it without opening it. And after opening, it won't be water proof. Search the forum if you are interested in alternatives, a good starting point is Espruino on your watch!

    • you have a PM :)
  • Sat 2020.01.25

    'no definition for the Storage module.'

    Not entirely sure what you are after, but has the actual source been inspected?

    https://github.com/espruino/Espruino/blob/master/src/jswrap_storage.c


    'too late for the Kickstarter party, and it's kind of expensive now'

    Last month I had a link for top ten hackable watches. looking now

    "kind of expensive" Relative term. I thought so too, until I started fetching detail. While I'm sure there are less expensive and cheap (meaning quality) CN equivalents, most started around $150 and up. So one can see, Bangle.js is nicely priced.

  • I meant that the @types/espruino Typescript definition doesn't have the Storage module covered. This thread is about Typescript.

  • Please put dates on all documentation pages

    https://www.espruino.com/Typescript+and+Visual+Studio+Code+IDE seems to be very out of date.

    Being able to use Visual Studio Code makes a huge difference. As nice as the browser IDE may be, it cannot compare to the IDE in capability.

    What can be done about making support a priority?

  • I don't understand why dates would help you in this case? Many pages haven't been updated in a while and are still fine.

    If you find problems with a page, you could click the link down the bottom to contribute updated information that was correct.

  • Same reason you put a use-by date on food packages. If the VSC post hasn't been updated in 2 years I know that it's a dead-end and no one cares. I can't update till it works well enough for me to learn.

    In this particular case, it seems to have been an incomplete effort and worth a reboot rather than a fix. I strongly want VSC/TS support but will start a new thread.

  • Thr 2020.04.09

    I'm with @BobFrankston on this and was even a recommendation I made two years ago. Having many users make suggestions would be a bad practice, primarily as most of us are in the learning process of how the bits-n-pieces work. How would any of us know whether the suggestion will even be accepted, let alone practical and follow established coding practices. Most won't even provide a link in the forums as a reference, so how could one expect someone with little experience to make suggestions. Probably why no one does. It takes time, it takes a great skill to get thought across in language. Not all were born with that ability. There needs to be one overseer, a date and copyright (which at least that is there). Edits to the page also need a date reference also, especially in cases where the underlying firmware may have changes causing an issue. Just found one recently with an Espruino Original, but dismissed making an update suggestion for the reasons here. Another issue that I keep running up against, and have butted heads with several in the forums, is that of coding style. This just crept up again, and I am arming myself with several links, one even by W3C.org that defends what I have been preaching all along, yet is dismissed in the Espruino world. How does one think that makes me feel, when those that wrote the specs and write the techniques, Charles Symoni I then take the same view point as I learned forty years ago, but get poo-pooed as it is believed the new teaching is somehow better? Reminds me of the B.S. our country is going through with the 'New Math' concept now being taught from which on their first job, recent grads aren't even able to count change! Practices and techniques were established for a reason. Imagine many flavors of coding technique examples and the difficulaties for someone just getting started would face, stymied and bewildered at which direction they should go. The change log should be date stamped along with the version, so one has an idea if something they read in the forum applies to the version they have. One of the reasons I have always dated my posts as a time reference.      my 0.02 worth

  • @Robin, there is no need to add a extra timestamp to you post because the forum does it for you. Click on the time information left to post number to switch from since to timestamp.


    2 Attachments

    • 3CF671F1-6D80-490E-A708-5DEF3BB7DD76.jpeg
    • BBCFC894-38BA-408B-877D-33845D23CBF7.jpeg
  • I think if a tutorial / guide includes third party code/module/something, a version number would be really helpful. Most likely more informative than a simple last modified timestamp. (You mean last modified date on the docs site. For some reason Robin and / or MaBe seems to think about timestamp here?)

    And a "support status" of the thing. Some JS modules state something like "Module xy is extremely beta.".

    The docs site in my experience:

    • Information about official Espruino's is usually pretty up to date. If there is a breaking change, usually the docs are updated, or someone notices and pings Gordon.
    • Info about ESP8266 and ESP32, is a bit outdated - that's community effort...
    • Info about third party stuff that don't get enough use, like VSC/TS integration - well, yeah :/

    On the other hand: if there is no breaking change, stuff works just as it worked years ago, should someone just crawl the whole docs site, and bump last modified if it still works?

    The link at the bottom of the page is useful: Last updated, and also list of commits, so you can the see changes as well.

  • Fri 2020.04.10

    'The link at the bottom of the page is useful: Last updated, and also list of commits, so you can the see changes as well.'

    Could this be a browser configuration thing? I just loaded the page in question, and there isn't a link at page bottom as described above.

    https://www.espruino.com/Typescript+and+Visual+Studio+Code+IDE



    @MaBe, thank you, learn something every day. Amazing how I've used the forum for three years now, and although I knew the blue number sign and numerical value was a post numbering hyperlink, never dawned on me as it is not intuitive to click on the adjacent time ago text. The main reason I date entries is I keep a running ASCII text file to speed searching to locate tips and links for speedy responses to forum requests. Text file searching using 'Find' is superior in comparrison to searching the forum, as my mental model is in chronological order. Remembering back, 'Oh, I wrote that around six weeks ago' aids in the speed to locate quickly. We each have our own tricks.

  • The link goes directly to the source markdown file on Github, and you have everything there


    1 Attachment

    • 2020-04-10 16_45_55-.png
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Typescript and BangleJS

Posted by Avatar for PiOfThings @PiOfThings

Actions