TypeScript
Overview
In Tuono, TypeScript is a first-class citizen.
tuono
packages are written entirely in TypeScript, allowing developers
to benefit from strong type checking that enhances code reliability and
ensures correctness when using its functions and modules.
Automatic Type Generation
Typically, types need to be defined twice: first in the Rust handlers and then in the React components/routes to consume the backend payload.
Duplicating the same interfaces is error-prone and can lead to production bugs.
To simplify development, tuono
enables automatic TypeScript type generation
for all structs
and enums
defined in any Rust file.
The Type
Trait
Any struct or enum can be derived
with the Type
trait, and the corresponding
TypeScript interface will be automatically generated on the frontend.
For example, for the following struct declaration:
The corresponding TypeScript type will be:
And it can be accessed via import from tuono/types
:
Serde Support
To pass the payload to React, the data must be deserialized,
and tuono
uses serde as the default serializer/deserializer.
tuono
supports all of serde's modifiers, ensuring that the generated TypeScript
type matches the payload sent to the frontend.
⚠️ Note: Manually serialized elements cannot be automatically generated.
Inspiration
This feature is strongly inspired by the ts_rs crate.
Edit page