{"id":19747,"library":"eslint-plugin-expect-type","title":"eslint-plugin-expect-type","description":"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.","status":"active","version":"0.6.2","language":"javascript","source_language":"en","source_url":"https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type","tags":["javascript","dtslint","d.ts","eslint","tslint","plugin","config","rule","typescript"],"install":[{"cmd":"npm install eslint-plugin-expect-type","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-expect-type","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-expect-type","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for parsing TypeScript with type information.","package":"@typescript-eslint/parser","optional":false},{"reason":"Required peer dependency – the plugin runs inside ESLint.","package":"eslint","optional":false},{"reason":"Required peer dependency for type checking and resolving type assertions.","package":"typescript","optional":false}],"imports":[{"note":"CommonJS users must add .default: require('eslint-plugin-expect-type/configs/recommended').default","wrong":"const expectType = require('eslint-plugin-expect-type/configs/recommended')","symbol":"default","correct":"import expectType from 'eslint-plugin-expect-type/configs/recommended'"},{"note":"rules is a named export, not available as a default import.","wrong":"const { rules } = require('eslint-plugin-expect-type')","symbol":"rules","correct":"import { rules } from 'eslint-plugin-expect-type'"},{"note":"The default export is the plugin object, not a named export named 'expectType'.","wrong":"import { expectType } from 'eslint-plugin-expect-type'","symbol":"plugin","correct":"import expectTypePlugin from 'eslint-plugin-expect-type'"}],"quickstart":{"code":"// eslint.config.js\nimport expectType from 'eslint-plugin-expect-type/configs/recommended';\nexport default [\n  expectType,\n  {\n    files: ['**/*.ts'],\n    rules: {\n      'expect-type/expect': 'warn',\n      'expect-type/expect-error': 'error',\n    },\n  },\n];\n\n// my-file.ts\nlet value = 9001;\n//  ^? let value: number\n\n// $ExpectError\nvalue = \"over nine thousand\";\n\n// $ExpectType number\n9001;\n\n// $ExpectTypeSnapshot [\"number\"]\ntype X = 1;","lang":"typescript","description":"Shows how to configure the plugin in flat config and use $ExpectType, $ExpectError, ^?, and $ExpectTypeSnapshot."},"warnings":[{"fix":"Migrate to explicit versionsToTest array in plugin options if needed.","message":"v0.6.0 adds versionsToTest option but may require updating configuration if you used the old undocumented API.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Upgrade to >=0.6.1 to avoid potential out-of-memory crashes.","message":"The 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.","severity":"gotcha","affected_versions":"<0.6.1"},{"fix":"Use const expectType = require('eslint-plugin-expect-type/configs/recommended').default;","message":"CommonJS users must use require('...').default when importing the configs/recommended path.","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Switch to flat configuration using import expectType from 'eslint-plugin-expect-type/configs/recommended'.","message":"The legacy ESLint config format (plugin:expect-type/recommended) is deprecated in favor of flat config.","severity":"deprecated","affected_versions":">=0.6.0"},{"fix":"Place the comment on its own line immediately above the line to be checked.","message":"$ExpectType and $ExpectError comments must be on the line before the expression or statement, not on the same line.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Write: let value = 9001; //  ^? let value: number","message":"The ^? Twoslash hover type comment must be placed directly after the variable/expression, with exactly one space between the variable and //.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install eslint-plugin-expect-type --save-dev","cause":"Plugin is not installed in the project's node_modules.","error":"Error: Failed to load plugin 'expect-type' declared in 'plugins': Cannot find module 'eslint-plugin-expect-type'"},{"fix":"Use require('eslint-plugin-expect-type/configs/recommended').default","cause":"Using require() on configs/recommended without .default in CommonJS.","error":"TypeError: expectType is not a function"},{"fix":"Enable 'expect-type/expect' rule in ESLint config and ensure the comment is on its own line before the expression.","cause":"The $ExpectType comment is used but the expect rule is not enabled or the comment syntax is incorrect.","error":"ESLint: Unexpected $ExpectType comment (expect-type/expect)"},{"fix":"Set parser: '@typescript-eslint/parser' in ESLint config for TypeScript files.","cause":"TypeScript syntax used in a .js file without @typescript-eslint/parser configured.","error":"Parsing error: Invalid or unexpected token"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}