
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
Runtime deserialization for TypeScript interfaces and type aliases
Read the blog post for a high level summary
TypeScript's structural typing system offers a powerful way to represent the shape of data. Data delivered across systems is, by default, not validated. A developer version can use type assertions to "cast" untrusted input to the expected type, but this is often done in an insecure way. Developers will usually write code that validates input data and coerces it to the right type.
tserial automates this process and offers a way to securely deserialize data at runtime.
npm install tserial --save-dev
yarn add tserial --dev
The CLI and Node API use the same underlying modules. Both generate file content. The CLI takes care of writing the file to the file system, while the Node API just returns string content.
In either mode, it's highly recommended to use a formatter like prettier to format the generated code. No attempt has been made to autogenerate well-formatted code.
# all options
tserial --help
# minimal command, use tsconfig.json at project root and default tag identifier
tserial --out ./path/to/generated_file.ts
# custom tsconfig
tserial --out ./path/to/generated_file.ts --tsconfig some-custom-tsconfig.json
# custom tag name (defaults to serializable)
# custom tsconfig
tserial --out ./path/to/generated_file.ts --tag myCustomTag
# deno imports
tserial --out ./path/to/generated_file.ts --deno
Check out render-content in renderer tests for an example of how the test suite calls the Node API.
Direct use of the Node API will allow greater flexibility within existing build systems, but the CLI may be faster to start with.
FAQs
Runtime validation for TypeScript type expressions
We found that tserial demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.