npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@qur/typetest

v1.0.7

Published

Testing typescript types

Readme

Testing Typescript Types

Lost confidence in types you created? You came to the right place.

What

A library for testing very complex types: with generics, unions, intersections, conditionals, inferings etc.

Why

You don't need to test if primitive types like string or boolean work correctly. Because they were tested by the TypeScript team. Now when you create ultra-complex type you are not that sure about type working as intended anymore.

Who

For those typescript developers who want to be sure that the type they created works as expected.

Example

Below is the structure of test files.

test
|__qur-typetest
   |__file1.ts
   |__file2.ts
   |__file3.ts

For simplicity we show example with simple types.

file1.ts:

const str: string = "foo"

file2.ts:

// tt:throws:Type '1' is not assignable to type 'string'.
const str: string = 1

file3.ts:

// tt:throws:Foo some wrong error message
const str: string = 1

Note: each test file should have at least one export or import expression. This way Typescript compiler would consider those files as modules, i.e. isolated code blocks. Otherwise for the example above tsc would generate errors Cannot redeclare block-scoped variable 'str'. Because of this reason, add this in the end of each files:

export {}

Result:

  ✓ test/qur-typetest/file1.ts
  ✓ test/qur-typetest/file2.ts
  ✗ test/qur-typetest/file3.ts

  test/qur-typetest/file3.ts was expected to fail with a message

    Foo some wrong error message

  but failed with

    Type '1' is not assignable to type 'string'.

  at test/qur-typetest/file3.ts:2:55

  1/3 failed
  2/3 passed

Install

npm install @qur/typetest --save-dev

Add test/qur-typetest to the exclude option of your tsconfig.json

"compilerOptions": {},
"exclude": [
  "test/qur-typetest"
]

Usage

Add a script to package.json

"scripts": {
  "typetest": "qur-typetest"
}

Do the following

npm run typetest -- init
echo "const str: string = 1" > test/qur-typetest/myTypeTest.ts
npm run typetest

CI

In order to include types testing to your Continuous Integration process, you should run typetest with other tests. Your test script in package.json could look like this:

"scripts": {
  "test": "mocha && typetest"
}

TODO

  • [x] Testing types
  • [ ] tests of this very library
  • [x] prettier errors
  • [x] Cli command "init" to create test/qur-typetest folder
  • [ ] Cli command "init" adds exclude to tsconfig.json
  • [ ] Cli command "create" to create test files

FAQ

Why should I add at least one export/import to a test file?

Because otherwise typescript thinks your files are parts of one code block, not an isolated module. Presence of export/import make typescript think that the file is a module and thus, it is isolated. You can omit using export/import until you actually encounter the described problem.

Name

Why "qur-typetest" and not just "typetest"? Because "qur" is going to be an ecosystem of libraries, it is work in progress now. Also this is done in order to avoid collisions with probably existing "test/typetest" folders. Also, npm just not allowed to create "typetest" named library.