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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-expect-error-validator

v0.0.5

Published

Since ts-expect-error does not have the ability to specify only the errors that we want to ignore, and instead suppresses all errors, it makes managing errors more challenging. This package provides a command-line tool to validate expected TypeScript erro

Downloads

457

Readme

TS Expected Errors Validator

Since ts-expect-error does not have the ability to specify only the errors that we want to ignore, and instead suppresses all errors, it makes managing errors more challenging. This package provides a command-line tool to validate expected TypeScript errors with the main goal of making error management easier.

Installation

Install the package:

yarn add -D ts-expect-error-validator

An example of usage:

class User {
   // Specify only a TS code for validation
   // @ts-expect-error [TS6133]
   private myNumber: string | undefined;
}

function getMyData(): string | undefined {
   return 'myData';
}

// Specify the message and a TS code for validation for `strict` mode
// @ts-expect-error [TS2532 - Object is possibly 'undefined']
getMyData().length;

// Other approach for ignoring a line:
getMyData().length; // @ts-expect-error [TS2532]

// Specify several TS code errors for validation for a line: 
// @ts-expect-error [TS2322, TS6133]
const object: { a: number } = { b: 5 };

// Specify several TS code errors with message description for validation
// @ts-expect-error [TS6133 - 'object' is declared but its value is never read, TS2322 - Type '{ b: number; }' is not assignable to type '{ a: number; }']
const sample: { a: number } = { b: 5 };

By default, the file extensions analyzed are tsx and ts.

Cli Options:

| Option | Description | |---------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | --tsConfigPath=<PATH> | Path to the tsconfig.json file to use. Defaults to the tsconfig.json in the current directory. | | --restore | Since we have to change all @ts-expect-error to something else, this changes the content file. You can use this option to restore changed files. | | --sourcePath=<PATH> | Path to the directory or the file containing @ts-expect-error to validate. You can specify several folders or files to make search more productive. | | --outputFormat=<FORMAT> | The output format. Can be either json or human. Defaults to human. | | --quiet | If present, suppresses all output except for report results. | | --validationMode=<MODE> | Specifies the validation mode to use. Can be either default or strict. In default mode, only the expected error codes are validated. In strict mode, the error code and the first line of the error description are validated. Notice that strict mode is in alpha version. Default is default. |

Example Usage:

//a package.json file
...
"scripts": {
  "ts-expect-error-validator": "ts-expect-error-validator --tsConfigPath=tsconfig.json --restore --sourcePath=src/myDir --sourcePath=src/someTsFile.ts --reportFormat=json --quiet"
}
...

//a cli comand
yarn ts-expect-error-validator

Hits

  • There is no need to scan all project sources for pull requests, instead it's more useful to check only the changed files by running this command:
     yarn ts-expect-error-validator $(git diff --name-only HEAD | grep "\.ts$" | xargs -I {} echo "--sourcePath={}" | tr '\n' ' ')
  • There is an ES Rule to ensure that code includes signatures for the validator.

License

This library is released under the MIT License.