`eslint-plugin-typescript-compat` is an ESLint plugin designed to ensure browser compatibility for TypeScript code by identifying the usage of ECMAScript APIs that are not supported by your configured target browsers. Currently at version 1.0.2, the plugin integrates with `mdn-browser-compat-data`, the TypeScript Compiler API, and `browserslist` to perform static analysis. Unlike `eslint-plugin-compat`, which focuses on JavaScript, this plugin specifically leverages TypeScript's type information to provide more accurate linting for TypeScript projects. It differentiates itself from `eslint-plugin-es` and `eslint-plugin-es-x` by supporting the detection of prototype and static methods (e.g., `Array.prototype.find`, `Array.from`), not just language syntax features. The plugin primarily supports JavaScript Built-in Objects and their methods, with future plans to expand to DOM API compatibility. Its release cadence appears to be driven by feature additions and bug fixes, with a focus on stability for its current scope. Users must configure `parserOptions.project` and `tsconfig.json` `lib` settings for proper functionality.
npm install eslint-plugin-typescript-compatVerified import paths — ran on the pinned version, not inferred.
Demonstrates the installation and configuration of `eslint-plugin-typescript-compat` across `package.json`, `.eslintrc.json`, and `tsconfig.json`, then provides TypeScript code that will trigger browser compatibility warnings for features unsupported in Internet Explorer 11, based on the `browserslist` configuration.
Ensure your `.eslintrc.json` includes `"parserOptions": { "project": "./tsconfig.json" }` pointing to your project's `tsconfig.json`.Update your `tsconfig.json` to include `"lib": ["ESNext", "DOM"]` (or similar for your target environment) to ensure TypeScript recognizes the APIs you intend to use.
Add a `browserslist` entry to your `package.json` (e.g., `"browserslist": ["ie 11", "last 2 versions"]`) or provide configuration via a dedicated `.browserslistrc` file.
Be aware that DOM API usage (e.g., `fetch`, `localStorage`) will not be linted for browser compatibility by this plugin at this time. Consider other tools for DOM API checks if needed.
Add a `"settings": { "polyfills": ["Array.prototype.find", "Promise"] }` block to your `.eslintrc.json` to list all polyfilled APIs.Add `"parserOptions": { "project": "./tsconfig.json" }` (or the correct path to your `tsconfig.json`) to your ESLint configuration.Update your `tsconfig.json` `compilerOptions.lib` to include `ESNext` or the specific ES version that defines the feature, e.g., `"lib": ["ESNext", "DOM"]`.
Ensure you have a valid `browserslist` configuration in your `package.json` (e.g., `"browserslist": ["ie 11"]`) or an `.browserslistrc` file at your project root.