u/WeirdEyeStudios

TL;DR: I made the switch to TypeScript for Spectacles development and haven’t looked back.

When TypeScript support was originally announced for Lens Studio, I’ll admit I wasn't excited. At the time I didn’t see the upside and I worried the extra time spent waiting for the compiler would slow down my workflow.

Then I started using it…

For the past six months every Lens project I’ve made has been written in TypeScript, and the compile-time issue is actually nonexistent. If you’re still on the fence, here are a few main reasons why TypeScript has made my development life significantly easier.

IntelliSense and Type Safety

I use VS Code for my development, and the IntelliSense support is a game-changer. It is extremely helpful to have the editor catch errors in real-time, such as passing the wrong argument type to a method.

Interfaces and Intentional Design

Using interfaces has forced me to be much more intentional with my code. They allow me to define a strict structure once and reuse it across an entire project. I used this heavily in a recent Spectacles Lens called 'Hot Wire'. By defining a central interface, I can update a structure in one place and have those changes automatically propagate and validate across all my scripts.

OOP (Classes and Inheritance)

By utilising Object Orientated Programming (OOP) principles like abstraction and polymorphism, I’ve been able to build more robust systems. I now develop large base classes and handle specific behaviours through subclasses.

This makes a massive difference when it comes to updating logic. If I need to tweak a core mechanic, I only have to change a few lines in the parent class rather than across multiple different scripts as I would need to in standard JavaScript.

Overall

Combining my points from above with a bunch of other quality of life improvements, I have really felt the benefits of making my Spectacles projects in TypeScript. Most of the official Spectacles samples are now written in TypeScript, which makes transitioning from a weekend experiment to a full prototype much faster. If you're considering the jump, I cannot recommend it enough. 🙂

reddit.com
u/WeirdEyeStudios — 25 days ago