tsync
A utility to generate types for other typed languages.
Currently, only typescript is supported.
Install
There are two parts to this:
-
The CLI tool:
cargo install tsync
-
The dependency for rust projects (to use the
#[tsync]
attribute; see usage below)/// Cargo.toml tsync = "X.Y.Z"
Usage
Mark structs with #[tsync]
as below:
/// rust_file.rs
use tsync;
/// Doc comments are preserved too!
/// Time in UTC seconds
type UTC = usize;
Then use the CLI tool:
And voilĂ !
/// types.d.ts
/* This file is generated and managed by tsync */
// Doc comments are preserved too!
interface Book {
name: string
chapters: Array<Chapter>
user_reviews: Array<string> | undefined
}
interface Chapter {
title: string
pages: number
}
// Time in UTC seconds
type UTC = number
Note: globs don't recurse on all platforms so try double or triple globbing!
Note: it might help to create multiple typing files for your project:
Errors
A list of files which can't be opened or parsed successfully are listed after executing tsync
. For other errors, using the --debug
flag may help find errors.
Docs
See tsync --help
for more information.
Feel free to open tickets for support or feature requests.
License
This tool is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.