
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
ts-exhaustive-check
Advanced tools
Exhaustive check for typescript type never.
This package has a single function called exhaustiveCheck
that just checks if a typescript type is of type never
.
It will save you one line of code in the default
case of switch
statements if you have strictNullChecks
enabled.
For more information see discriminated-unions and typescript issue 6155.
yarn add ts-exhaustive-check
import { exhaustiveCheck } from "ts-exhaustive-check";
interface Square {
kind: "square";
size: number;
}
interface Rectangle {
kind: "rectangle";
width: number;
height: number;
}
interface Circle {
kind: "circle";
radius: number;
}
type Shape = Square | Rectangle | Circle;
function area(s: Shape) {
switch (s.kind) {
case "square":
return s.size * s.size;
case "rectangle":
return s.width * s.height;
case "circle":
return Math.PI * s.radius * s.radius;
default:
return exhaustiveCheck(s);
}
}
Without this package the default
case in the switch
statement would have been this:
function area(s: Shape) {
switch (s.kind) {
...
default:
const _exhaustiveCheck: never = s;
return _exhaustiveCheck;
}
}
[1.0.0]
FAQs
Exhaustive check for typescript type never
The npm package ts-exhaustive-check receives a total of 459 weekly downloads. As such, ts-exhaustive-check popularity was classified as not popular.
We found that ts-exhaustive-check 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
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.