
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
ts-type-assert
Advanced tools
Type assertion library for TypeScript.
The library requires conditional types, so the minimum supported TypeScript version is 2.8.0.
$ npm i --save-dev ts-type-assert
or
$ yarn add -D ts-type-assert
Let's suppose you want to declare a type that is a union of two other types. One type is built-in and the other one is custom:
import { ComponentProps } from 'react';
type NativeButtonProps = ComponentProps<'button'>;
interface CustomButtonProps {
error?: string;
warning?: string;
}
type ButtonProps = NativeButtonProps & CustomButtonProps;
How do you make sure that none of the properties from CustomButtonProps overlap those defined in NativeButtonProps? ts-type-assert is to the rescue! Just use MergePropsWithoutOverlapping utility type:
import { Assert, MergePropsWithoutOverlapping } from 'ts-type-assert';
// ...
type ButtonProps = Assert<
MergePropsWithoutOverlapping<NativeButtonProps, CustomButtonProps>
>;
In case props overlap you will get a (somewhat) handy error message:
type CustomButtonProps = {
disabled?: string;
};
error TS2344: Type 'AssertionError<"Some properties of T1 and T2 overlap", { __properties: "disabled"; }>' does not satisfy the constraint 'AssertionSuccess<unknown>'.
Type 'AssertionError<"Some properties of T1 and T2 overlap", { __properties: "disabled"; }>' is missing the following properties from type 'AssertionSuccess<unknown>': __value, __asserted
10 export type ButtonProps = Assert<MergePropsWithoutOverlapping<NativeButtonProps, CustomButtonProps>>;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Is<T1, T2>Checks whether T1 extends T2.
import { User } from './generated-models';
type UserId = Assert<Is<User['id'], number>>;
These two are very similar, but require you to actually write code (call dummy assert function) instead of using plain types:
Other utility types libraries:
FAQs
Type assertion library for TypeScript
We found that ts-type-assert 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.