leopard-js / sb-edit

Javascript library for manipulating Scratch project files
MIT License
54 stars 15 forks source link

Update sb-edit to latest TypeScript + new TypeScript idioms #92

Closed adroitwhiz closed 11 months ago

adroitwhiz commented 1 year ago

TypeScript's undergone a lot of improvement since this project started. We could probably make use of a lot of new TS features in order to better infer and narrow types, especially for block inputs.

The way that people write TypeScript has also changed--for instance, TypeScript gained the unknown type, which represents a type that is a supertype of every other type. This replaces the unsafe any type, which can be used to violate type safety. Unfortunately, this codebase makes extensive use of any.

It's probably worth upgrading this project to use modern TypeScript. Since eliminating any could change the public API, it may be worth releasing a new major version?

adroitwhiz commented 1 year ago

image

my typescript-fu is too silly :pensive:

towerofnix commented 1 year ago

Thanks! This is something to investigate, for sure — sb-edit is my main exposure to TypeScript, honestly, so I'm not versed in any recent additions. 😅

I'll mark here the existing (block.inputs.VARIABLE.value as { id: string }).id pattern mentioned here. There are plenty of other examples of casting "assumptions" about block inputs which TypeScript isn't picking up on (or, you know, is correctly warning us about in the case of arbitrarily shaped inputs from unknown blocks!).