eslint-plugin-expect-type
TypeScript icon, indicating that this package has built-in type declarations

0.4.0Β β€’Β PublicΒ β€’Β Published

eslint-plugin-expect-type

ESLint plugin with `^?` Twoslash, `$ExpectError`, and `$ExpectType` type assertions. 🧩

All Contributors: 10 πŸ‘ͺ Codecov Test Coverage Contributor Covenant License: Apache-2.0 Style: Prettier TypeScript: Strict npm package version Contributor Covenant

let value = 9001;
//  ^? let value: number

// $ExpectError
value = "over nine thousand";

// $ExpectType number
9001;

Installation

Make sure you have TypeScript and @typescript-eslint/parser installed, then install the plugin:

npm i -D eslint-plugin-expect-type

See typescript-eslint's Getting Started docs for how to run ESLint on TypeScript files.

Usage

Add the following options to your ESLint configuration file:

import expectType from "eslint-plugin-expect-type/configs/recommended";

export default [
	// your other ESLint configurations
	expectType,
];

Then, you'll be able to use ^?, $ExpectError, $ExpectType, and $ExpectTypeSnapshot comments in code assert on types.

Usage (Legacy Config)

If you're still using the legacy ESLint configuration file format:

{
	"extends": ["plugin:expect-type/recommended"],
	"plugins": ["expect-type"]
}

Rules

πŸ’Ό Configurations enabled in.
βœ… Set in the recommended configuration.
πŸ”§ Automatically fixable by the --fix CLI option.
πŸ’­ Requires type information.

Name Description πŸ’Ό πŸ”§ πŸ’­
expect Expects type error, type snapshot, or type. βœ… πŸ”§ πŸ’­

References

You might consider using other popular type assertion libraries in the TypeScript ecosystem:

  • expect-type: Provides functions that return assorted generic type assertion methods, such as expectTypeOf('abc').toMatchTypeOf<string>().
  • ts-expect: Provides generic type assertion function, used like expectType<string>('abc')().
  • tsd: Allows writing tests specifically for .d.ts definition files.
  • Vitest: Includes assertType and expectTypeOf assertions.

TypeScript Version Support

eslint-plugin-expect-type mirrors the DefinitelyTyped TypeScript Support Window. Roughly, that's major versions of TypeScript less than 2 years old.

Appreciation

Many thanks to @ibezkrovnyi for creating the initial version and core infrastructure of this package! πŸ’–

Contributors

Batuhan Wilhelm
Batuhan Wilhelm

πŸ› πŸ’»
Colin
Colin

πŸ›
Dan Vanderkam
Dan Vanderkam

πŸ’» 🚧
Daniel Nagy
Daniel Nagy

πŸ›
Dominik Dorfmeister
Dominik Dorfmeister

πŸ“–
Igor Bezkrovnyi
Igor Bezkrovnyi

πŸ› πŸ’» πŸ“– 🚧
Josh Goldberg ✨
Josh Goldberg ✨

πŸ› πŸ’» πŸ“– 🚧 πŸš‡ πŸ€”
Russell Davis
Russell Davis

πŸ’»
detachhead
detachhead

πŸ€”
nirtamir2
nirtamir2

πŸ“–

πŸ’™ This package was templated with create-typescript-app.

Package Sidebar

Install

npm i eslint-plugin-expect-type

Weekly Downloads

3,916

Version

0.4.0

License

Apache-2.0

Unpacked Size

187 kB

Total Files

111

Last publish

Collaborators

  • danvk
  • joshuakgoldberg
  • igor.bezkrovnyi