Open andrey-kuprianov opened 3 years ago
Recommendation: Consider switching SwingSet kernel to TypeScript, or to track the type information automatically by other means.
As we have already discussed verbally with @andrey-kuprianov
As stated literally, we will not convert our code from JavaScript to TypeScript. However, Agoric has adopted the properjs style of using TypeScript types in jsdoc comments and arranging our tooling to engage the TypeScript type checker to check our code against those types. This provides most of the benefits of writing in TypeScript directly while avoiding two big security hazards of writing in TypeScript:
All that said, the point of @andrey-kuprianov 's recommendation is still correct. Most of that code is not adequately typed using these typescript-in-jsdoc type declarations. Improving that will have exactly the benefits @andrey-kuprianov states.
Surfaced from @informalsystems Agoric Audit of Agoric/agoric-sdk/SwingSet hash 23ed67c070a6ea04fb305d469283107b1d3d65f3
The SwingSet kernel is written in JavaScript, and thus uses weak and dynamic typing. This may lead to a lot of subtle and undetectable bugs, that would be easy to detect if a language with strict typing is used. Luckily, there is an easy JavaScript -> TypeScript migration path, that brings a lot of benefits early. Even a very quick experiment with renaming all SwingSet
.js
files into.ts
files, and running the TypeScript compiler, allowed to find these issues (among others):This only surfaces the problem; adding type annotations will definitely uncover more issues. The real problem with JavaScript is that it is too liberal, and allows to do modifications to the code locally, without considering the far-reaching effects of those changes. As a result, the programmer is forced to do manually the job of a type checker, which can be in fact easily automated to prevent serious bugs.
Recommendation: Consider switching SwingSet kernel to TypeScript, or to track the type information automatically by other means.