
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
common-expectations
Advanced tools
A small collection of common typescript functions for asserting and guarding types.
# using npm
npm install common-expectations
# or using yarn
yarn add common-expectations
exists<T>(value: T, message: string): void
A utility for asserting existence of a value when the type may be undefined
or null
.
import { exists } from "common-expectations";
// where use params returns a partial type where `id` maybe undefined.
const { id } = useParams<{ id: string }>();
exists(value, 'Expected id to be defined.')
This is intended only to be used in those rare cases where you know based on context that a value exists but the type system is unable to infer the fact. A good example of this is when using params in React Router.
isUnreachable(value: never, message?: string): void
A utility for helping check type exhaustiveness.
It will raise typescript type error when a values type is anything other than never
,
and will throw an error at runtime if a value is encountered.
import { isUnreachable } from "common-expectations";
type AnimalType = 'cat' | 'dog' | 'monkey';
function doSomthing(type: AnimalType) {
switch (type) {
case "cat":
case "dog":
case "monkey":
break;
default:
isUnreachable(type, `Encountered unexpected animal type: ${type}`);
}
}
FAQs
Typescript runtime assertions
We found that common-expectations 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.