New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More โ†’
Socket
Sign inDemoInstall
Socket

eslint-plugin-expect-type

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-expect-type

ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. ๐Ÿงฉ

  • 0.6.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

eslint-plugin-expect-type

ESLint plugin with `^?` Twoslash, `$ExpectError`, and `$ExpectType` type assertions. ๐Ÿงฉ

All Contributors: 13 ๐Ÿ‘ช Contributor Covenant Codecov Test Coverage License: Apache-2.0 npm package version TypeScript: Strict

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,
];

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:

{
	"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.

NameDescription๐Ÿ’ผ๐Ÿ”ง๐Ÿ’ญ
expectExpects type error, type snapshot, or type.โœ…๐Ÿ”ง๐Ÿ’ญ

References

You might consider using other popular libraries and tools that can run type assertions:

  • 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.
  • TSTyche: 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: 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

๐Ÿ›
Cรฉdric Exbrayat
Cรฉdric Exbrayat

๐Ÿ›
Dan Vanderkam
Dan Vanderkam

๐Ÿ’ป ๐Ÿšง
Daniel Nagy
Daniel Nagy

๐Ÿ›
Dominik Dorfmeister
Dominik Dorfmeister

๐Ÿ“–
Francesco Trotta
Francesco Trotta

๐Ÿ’ป ๐Ÿ›
Igor Bezkrovnyi
Igor Bezkrovnyi

๐Ÿ› ๐Ÿ’ป ๐Ÿ“– ๐Ÿšง
Josh Goldberg โœจ
Josh Goldberg โœจ

๐Ÿ› ๐Ÿ’ป ๐Ÿ“– ๐Ÿšง ๐Ÿš‡ ๐Ÿค” ๐Ÿ”ง
Russell Davis
Russell Davis

๐Ÿ’ป
Tom Mrazauskas
Tom Mrazauskas

๐Ÿ“–
detachhead
detachhead

๐Ÿค”
nirtamir2
nirtamir2

๐Ÿ“–

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

Keywords

FAQs

Package last updated on 29 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc