russelldavis / eslint-plugin-expect-type

ESLint plugin with $ExpectType, $ExpectError, and $ExpectTypeSnapshot type assertions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eslint-plugin-expect-type

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

9001;
// ^? number

// $ExpectError
const value: string = 9001;

// $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:

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

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

πŸ’Ό 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.

Appreciation

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

About

ESLint plugin with $ExpectType, $ExpectError, and $ExpectTypeSnapshot type assertions

License:Apache License 2.0


Languages

Language:TypeScript 97.9%Language:JavaScript 2.1%