Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshuakgoldberg/eslint-plugin-expect-type
ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. π§©
https://github.com/joshuakgoldberg/eslint-plugin-expect-type
eslint eslint-plugin expect-type typescript typescript-eslint
Last synced: 4 days ago
JSON representation
ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. π§©
- Host: GitHub
- URL: https://github.com/joshuakgoldberg/eslint-plugin-expect-type
- Owner: JoshuaKGoldberg
- License: apache-2.0
- Created: 2019-09-06T19:03:06.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-12T20:27:05.000Z (13 days ago)
- Last Synced: 2024-12-12T21:27:15.826Z (13 days ago)
- Topics: eslint, eslint-plugin, expect-type, typescript, typescript-eslint
- Language: TypeScript
- Homepage:
- Size: 2.79 MB
- Stars: 112
- Watchers: 4
- Forks: 5
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
eslint-plugin-expect-type
ESLint plugin with
^?
Twoslash,$ExpectError
, and$ExpectType
type assertions. π§©```ts
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:
```sh
npm i -D eslint-plugin-expect-type
```> See [typescript-eslint's Getting Started docs](https://typescript-eslint.io/docs) for how to run ESLint on TypeScript files.
## Usage
Add the following options to your [ESLint configuration file](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new):
```ts
import expectType from "eslint-plugin-expect-type/configs/recommended";export default [
// your other ESLint configurations
expectType,
];
```> For CommonJS, use `const expectType = require("eslint-plugin-expect-type/configs/recommended").default;`.
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](https://eslint.org/docs/latest/user-guide/configuring/configuration-files):
```json
{
"extends": ["plugin:expect-type/recommended"],
"plugins": ["expect-type"]
}
```## Rules
πΌ Configurations enabled in.\
β Set in the `recommended` configuration.\
π§ Automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
π Requires [type information](https://typescript-eslint.io/linting/typed-linting).| Name | Description | πΌ | π§ | π |
| :----------------------------- | :------------------------------------------ | :- | :- | :- |
| [expect](docs/rules/expect.md) | Expects type error, type snapshot, or type. | β | π§ | π |## References
You might consider using other popular libraries and tools that can run type assertions:
- **[expect-type](https://github.com/mmkal/expect-type)**: Provides functions that return assorted generic type assertion methods, such as `expectTypeOf('abc').toMatchTypeOf()`.
- **[ts-expect](https://github.com/TypeStrong/ts-expect)**: Provides generic type assertion function, used like `expectType('abc')()`.
- **[tsd](https://github.com/SamVerschueren/tsd)**: Allows writing tests specifically for `.d.ts` definition files.
- **[TSTyche](https://tstyche.org)**: A type testing tool that ships with `describe()` and `test()` helpers, `expect` style assertions and a mighty test runner which allows to use specified version of TypeScript.
- **[Vitest](https://vitest.dev/guide/testing-types.html)**: Includes `assertType` and `expectTypeOf` assertions.## TypeScript Version Support
`eslint-plugin-expect-type` mirrors the [DefinitelyTyped TypeScript Support Window](https://github.com/DefinitelyTyped/DefinitelyTyped/#support-window).
Roughly, that's major versions of TypeScript less than 2 years old.## Appreciation
Many thanks to [@ibezkrovnyi](https://github.com/ibezkrovnyi) for creating the initial version and core infrastructure of this package! π
## Contributors
Andrew Branch
π»
Batuhan Wilhelm
π π»
Colin
π
CΓ©dric Exbrayat
π
Dan Vanderkam
π» π§
Daniel Nagy
π
Dominik Dorfmeister
π
Francesco Trotta
π» π
Igor Bezkrovnyi
π π» π π§
Jake Bailey
π»
Josh Goldberg β¨
π π» π π§ π π€ π§
Russell Davis
π»
Tom Mrazauskas
π
detachhead
π€
nirtamir2
π
> π This package was templated with [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).