twoslash-eslint
raw JSON → 0.3.8 verified Sat Apr 25 auth: no javascript
ESLint-backed twoslash runner for annotating code examples with ESLint errors and warnings. Current stable version is 0.3.8, released on a monthly cadence. Key differentiators: integrates ESLint diagnostic results directly into twoslash code blocks, supports TypeScript v6 since v0.3.7, and is part of the twoslash monorepo. Experimental — breaking changes may not follow semver. Ships TypeScript types.
Common errors
error ERR_REQUIRE_ESM: require() of ES Module not supported ↓
cause Using CommonJS require() to import an ESM-only package.
fix
Use dynamic import: const m = await import('twoslash-eslint') or set your project to type: module.
error Cannot find module 'twoslash-eslint' ↓
cause Package not installed or missing from package.json dependencies.
fix
Run npm install twoslash-eslint (peer dep eslint must also be installed).
Warnings
breaking Since v0.3.0, TypeScript ^5.5.0 is explicitly required. Older TypeScript versions are unsupported. ↓
fix Upgrade TypeScript to >=5.5.0 or stay on v0.2.x if you need older TS support.
gotcha The package is experimental and breaking changes may not follow semver. ↓
fix Pin to a specific version and test upgrades carefully.
deprecated The `writeGlobalTypes` option was removed in v0.3.5 for Vue integration. ↓
fix Remove `writeGlobalTypes` from configuration. Use other Vue type handling mechanisms if needed.
Install
npm install twoslash-eslint yarn add twoslash-eslint pnpm add twoslash-eslint Imports
- createTwoslashESLint wrong
const createTwoslashESLint = require('twoslash-eslint')correctimport { createTwoslashESLint } from 'twoslash-eslint' - default
import twoslashESLint from 'twoslash-eslint' - TypeScriptESLintRunner wrong
import { TypeScriptESLintRunner } from 'twoslash'correctimport { TypeScriptESLintRunner } from 'twoslash-eslint'
Quickstart
import { createTwoslashESLint } from 'twoslash-eslint'
import { createTwoslash } from 'twoslash'
const twoslashESLint = createTwoslashESLint({
eslint: {
// ESLint options
overrideConfig: {
rules: { 'no-unused-vars': 'warn' }
}
}
})
const result = createTwoslash({
code: 'let x = 1',
defaultCompilerOptions: { strict: true },
customRunners: [twoslashESLint]
})