
Product
Introducing Supply Chain Attack Campaigns Tracking in the Socket Dashboard
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.
Easy-to-use library that implements opaque types in TypeScript!
Install ts-opaque through npm:
$ npm install ts-opaque
An opaque type, in TypeScript, is a type whose true structure is obfuscated to the compiler at compile-time. These types can make your code more type safe, secure, easier to refactor, and faster!
While Flow has an opaque keyword for creating opaque types, TypeScript does not; this package is my solution.
import Opaque from "ts-opaque";
interface User {
readonly id: Opaque<number, User>;
name: string;
}
interface Post {
readonly id: Opaque<number, Post>;
readonly authorId: User["id"];
title: string;
body: string;
}
let myUser: User = {
// Error, type 'number' is not assignable to type 'Opaque<number, User>'
id: 1,
name: "John Doe",
};
myUser = {
id: 1 as User["id"],
name: "John Doe",
};
let myPost: Post = {
// Error, type 'number' is not assignable to type 'Opaque<number, Post>'
id: 1,
// Error, type 'number' is not assignable to type 'Opaque<number, User>'
authorId: 1,
title: "ts-opaque",
body: "It's a pretty cool package.",
};
myPost = {
id: 1 as Post["id"],
authorId: myUser.id,
title: "ts-opaque",
body: "It's a pretty cool package.",
};
There are other types and helper function ts-opaque exports as well! Check out the API below.
Opaque - Create an opaque type.Others have made fantastic packages to implement opaque types in TypeScript. While these implementations are flawless in their functionality, ts-opaque brands its opaque types with symbol keys, hiding them directly from your IDE's intellisense or its equivalent. ts-opaque is also distributed with helper functions and types to manipulate and use opaque types easily. Spread some love to these works:
This package is available as open source under the terms of the MIT License.
FAQs
Easy-to-use library that implements opaque types in TypeScript!
We found that ts-opaque 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.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.

Research
Malicious PyPI package sympy-dev targets SymPy users, a Python symbolic math library with 85 million monthly downloads.

Security News
Node.js 25.4.0 makes require(esm) stable, formalizing CommonJS and ESM compatibility across supported Node versions.