
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
typescript-test-utils
Advanced tools
Helper types for testing your package exported types
I have notice some issues with typescript if your types are too complex, so I recommend using assertTrue and assertFalse instead of assert
You test them with the assert method ( wich is just a placeholder, it doesn't run anything ) and the type helpers
import {
assert,
assertTrue,
assertFalse,
HasProperties
} from "typescript-test-utils";
assertTrue<true>(); // ok
assertTrue<false>(); // nop
assertFalse<true>(); // nop
assertFalse<false>(); // ok
assert<true>(true); // ok
assert<false>(true); // nop
type MyType = { a: string };
assertTrue<HasProperties<MyType, "a">>(); // ok
assertFalse<HasProperties<MyType, "a">>(); // nop
assertTrue<HasProperties<MyType, "b">>(); // nop
assertFalse<HasProperties<MyType, "b">>(); // ok
And just run tsc on your test files to check for type errors
{
"scripts": {
"test": "tsc --noEmit src/*.test.ts"
}
}
There are currently some implemented, if you have any idea for a new one send a PR or open an issue
import { assert, HasProperties, Extends, Equals, Not } from "typescript-test-utils";
HasProperties<{ a: string, b: number }, "a" | "b"> // true
HasProperties<{ a: string, b: number }, "a" | "c"> // false
Extends<{ a: string, b: string }, { a: string }> // true
Extends<{ a: string, b: string }, { c: string }> // false
Equals<{ a: string }, { a: string }> // true
Equals<{ a: string, b: string }, { a: string }> // false
Not<true> // false
Not<false> // true
Not<Equals<{ a: string, b: string }, { a: string }>> // true
You only need to make a type that returns true or false, for example:
type Not<T extends boolean> = T extends true ? false : true;
or
type Extends<T, K> = T extends K ? true : false;
These are the definitions of the Not and Extends helpers
FAQs
Helper types for testing your package exported types
The npm package typescript-test-utils receives a total of 14 weekly downloads. As such, typescript-test-utils popularity was classified as not popular.
We found that typescript-test-utils 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
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.