Method Chaining

Teasim heavily encourages the use of method chaining.

Because Teasim's type system is complex, methods usually introduce a new type to the instance.

Using method chaining will help save that new type reference.

For example:

const app = new Teasim()
  .state("build", 1)
  // Store is strictly typed
  .get("/", ({ store: { build } }) => build)
  .listen(3000);

Using this, state now returns new TeasimInstance type, introducing build into store and replace the current one.

Method chaining now saves that new type and passes it to get, which is why get now has type access of build.

Without using method chaining, Teasim doesn't save the new type when introduced, leading to no type inference.

const app = new Teasim();

app.state("build", 1);

// Doesn't have access to build
app.get("/", ({ store: { build } }) => build);

app.listen(3000);

That's why Teasim encourage use of method chaining, not only that it reduces redundant usage of the app. prefix, but also to provide better type inference.