spaghetti - Type-safe APIs for compile-to-JavaScript modules

  •        0

Spaghetti modules are written in compile-to-JS languages like [TypeScript]( and [Haxe]( Each module's API is defined in a [Spaghetti Interface Definition file](/../../wiki/Spaghetti Syntax). Here's an example of a typical API definition:```module com.example.greeterinterface Greeter { string sayHello(string user)}Greeter createGreeter()```Based on this abstract definition, Spaghetti ensures type safety on both the implementor and the caller side of an API:* **checking if a module implements its API properly** is done via generated interfaces that the module must implement. This way the compiler can check if you've made a mistake or have forgotten something. From the above example, the generated code for the `Greeter` Spaghetti interface in a TypeScript module looks like this: ```typescript /* Generated by Spaghetti */ module com.example.greeter { export interface Greeter { sayHello(user:string):string; } } ```* **checking if a module is calling the right API of its dependency** is also done via code generation. Spaghetti generates language-specific proxy classes to access other modules in a type-safe way, based on those modules' Spaghetti APIs. Here's how you would use `Greeter` from an Haxe module: ```haxe import com.example.greeter.GreeterModule; // ... var greeter = GreeterModule.createGreeter(); trace(greeter.sayHello("World")); ```If you make a typo in `sayHello`, or try to pass a number as its parameter, the Haxe compiler will fail with an error.For a detailed explanation of the steps to building a Spaghetti application, see [Workflow on the wiki](../../wiki/Workflow).



Related Projects