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-typeVerified import paths — ran on the pinned version, not inferred.
Shows how to configure the plugin in flat config and use $ExpectType, $ExpectError, ^?, and $ExpectTypeSnapshot.
Migrate to explicit versionsToTest array in plugin options if needed.
Upgrade to >=0.6.1 to avoid potential out-of-memory crashes.
Use const expectType = require('eslint-plugin-expect-type/configs/recommended').default;Switch to flat configuration using import expectType from 'eslint-plugin-expect-type/configs/recommended'.
Place the comment on its own line immediately above the line to be checked.
Write: let value = 9001; // ^? let value: number
npm install eslint-plugin-expect-type --save-dev
Use require('eslint-plugin-expect-type/configs/recommended').defaultEnable 'expect-type/expect' rule in ESLint config and ensure the comment is on its own line before the expression.
Set parser: '@typescript-eslint/parser' in ESLint config for TypeScript files.