Registry / testing / eslint-plugin-expect-type

eslint-plugin-expect-type

JSON →
library0.6.2jsnpmunverified

ESLint plugin that adds Twoslash-style type assertions ($ExpectType, $ExpectError, $ExpectTypeSnapshot) and the ^? hover type comment. Version 0.6.2 is the latest stable release as of early 2025, with active development and frequent releases (0.4.x to 0.6.x in rapid succession). Unlike runtime assertion libraries (expect-type, ts-expect), this plugin works at the ESLint linting level without test runners. Requires @typescript-eslint/parser ≥6, ESLint ≥7, and TypeScript ≥4. Unique for inline type assertions in comments, enabling type-level testing in any file linted by ESLint.

npm install eslint-plugin-expect-type
INSTALL
IMPORT
SIG · ESLINT-PLUGIN-EXPE
E
eslint-plugin-expect-type
testingjavascriptv0.6.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import expectType from 'eslint-plugin-expect-type/configs/recommended'
const expectType = require('eslint-plugin-expect-type/configs/recommended')
CommonJS users must add .default: require('eslint-plugin-expect-type/configs/recommended').default
rules
import { rules } from 'eslint-plugin-expect-type'
const { rules } = require('eslint-plugin-expect-type')
rules is a named export, not available as a default import.
plugin
import expectTypePlugin from 'eslint-plugin-expect-type'
import { expectType } from 'eslint-plugin-expect-type'
The default export is the plugin object, not a named export named 'expectType'.

Shows how to configure the plugin in flat config and use $ExpectType, $ExpectError, ^?, and $ExpectTypeSnapshot.

// eslint.config.js import expectType from 'eslint-plugin-expect-type/configs/recommended'; export default [ expectType, { files: ['**/*.ts'], rules: { 'expect-type/expect': 'warn', 'expect-type/expect-error': 'error', }, }, ]; // my-file.ts let value = 9001; // ^? let value: number // $ExpectError value = "over nine thousand"; // $ExpectType number 9001; // $ExpectTypeSnapshot ["number"] type X = 1;
Debug
Known issues
breakingv0.6.0 adds versionsToTest option but may require updating configuration if you used the old undocumented API.
fix
Migrate to explicit versionsToTest array in plugin options if needed.
affects: >=0.6.0
gotchaThe plugin relies on TypeScript's language service and can be memory-intensive for large projects; a heap cache limit was introduced in v0.6.1.
fix
Upgrade to >=0.6.1 to avoid potential out-of-memory crashes.
affects: <0.6.1
gotchaCommonJS users must use require('...').default when importing the configs/recommended path.
fix
Use const expectType = require('eslint-plugin-expect-type/configs/recommended').default;
affects: >=0.4.0
deprecatedThe legacy ESLint config format (plugin:expect-type/recommended) is deprecated in favor of flat config.
fix
Switch to flat configuration using import expectType from 'eslint-plugin-expect-type/configs/recommended'.
affects: >=0.6.0
gotcha$ExpectType and $ExpectError comments must be on the line before the expression or statement, not on the same line.
fix
Place the comment on its own line immediately above the line to be checked.
affects: >=0.1.0
gotchaThe ^? Twoslash hover type comment must be placed directly after the variable/expression, with exactly one space between the variable and //.
fix
Write: let value = 9001; //  ^? let value: number
affects: >=0.1.0
Errors
Common errors & fixes
Error: Failed to load plugin 'expect-type' declared in 'plugins': Cannot find module 'eslint-plugin-expect-type'
Plugin is not installed in the project's node_modules.
fix
npm install eslint-plugin-expect-type --save-dev
TypeError: expectType is not a function
Using require() on configs/recommended without .default in CommonJS.
fix
Use require('eslint-plugin-expect-type/configs/recommended').default
ESLint: Unexpected $ExpectType comment (expect-type/expect)
The $ExpectType comment is used but the expect rule is not enabled or the comment syntax is incorrect.
fix
Enable 'expect-type/expect' rule in ESLint config and ensure the comment is on its own line before the expression.
Parsing error: Invalid or unexpected token
TypeScript syntax used in a .js file without @typescript-eslint/parser configured.
fix
Set parser: '@typescript-eslint/parser' in ESLint config for TypeScript files.
Upgrade
Version history
0.6.2latest on npm
Audit
Dependencies
@typescript-eslint/parserrequiredRequired peer dependency for parsing TypeScript with type information.
eslintrequiredRequired peer dependency – the plugin runs inside ESLint.
typescriptrequiredRequired peer dependency for type checking and resolving type assertions.
Agent activity
2 hits · last 30 days
node
2
Resources