
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@withgraphite/retype
Advanced tools
Reified types for Typescript.
Retype gives you a way declare types in a way that the typesystem can read and can also be checked at runtime. The need came from declaring API routes which we wanted to be able to parse for developer experience wins, while still being able to validate at runtime.
yarn add @screenplaydev/retype
import * as t from "@screenplaydev/retype";
const isBlogPost = t.shape({
title: t.string,
content: t.string,
author: t.optional(
t.shape({
name: t.string,
age: t.number,
})
),
});
type TBlogPost = t.TypeOf<typeof isBlogPost>;
isBlogPost({
title: "Hello world",
content: "Lorem ipsum...",
}); // returns true
isBlogPost({
foo: "bar",
}); // returns false
t.nulltype
t.number
t.string
t.array(t.string)
t.shape({memberName: t.string})
t.undefinedtype
t.literal("FOO" as const)
t.tuple([t.string, t.number])
t.union(t.string, t.number)
t.intersection(t.shape({name: t.string}), t.shape({age: t.number}))
t.unionMany([t.number, t.string])
t.intersectMany([t.shape({name: t.string}), t.shape({age: t.number})])
t.literals(["FOO", "BAR"] as const)
t.optional(t.string)
t.nullable(t.string)
Adding other validators is very simple, just add a function which returns a type predicate:
export const string = (value: unknown): value is string => {
return typeof value === "string";
};
Heavily inspired by io-ts and runtypes.
(More alternatives here: https://www.typescriptneedstypes.com/)
MIT Licensed (see LICENSE.txt)
Copyright 2021, Screenplay Studios Inc.
FAQs
Reified types for Typescript.
We found that @withgraphite/retype demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.