A TypeScript Language Service Plugin for detecting and highlighting deprecated symbols in TypeScript and JavaScript projects.
BEFORE | AFTER |
AFTER: The plugin automatically highlights deprecated symbols directly in the code editor for immediate visibility.
You can install ts-extended-deprecation-plugin
as an npm package:
# Install the package locally
npm install --save-dev ts-extended-deprecation-plugin
Or with Yarn:
yarn add -D ts-extended-deprecation-plugin
Note: If you're using Visual Studio Code, you'll have to use the first approach above, with a path to the module, or run the "TypeScript: Select TypeScript Version" command and choose "Use Workspace Version", or click the version number between "TypeScript" and 😃 in the lower-right corner. Otherwise, VS Code will not be able to find your plugin. See https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin#testing-locally
To use this plugin in your TypeScript project, add it to your tsconfig.json
:
{
"compilerOptions": {
"plugins": [
{
"name": "ts-extended-deprecation-plugin"
}
]
}
}
This configuration will enable the plugin and allow it to detect deprecated symbols in your TypeScript/JavaScript code.
The ts-extended-deprecation-plugin
hooks into the TypeScript Language Service, detecting any symbols marked with @deprecated
in your project. When it finds a deprecated symbol, it does the following:
- Hover Tooltip: Displays a hover tooltip in your editor with a deprecation message.
- Diagnostics: Adds a warning to the diagnostics view with details about the deprecated symbol, file, and location.
You can extend the functionality with custom options in tsconfig.json
. Currently, this plugin works automatically without additional configurations, but future releases may allow more granular control over the behavior.
Consider this code:
// In your file.ts
/**
* @deprecated Use newFunction instead
*/
export function oldFunction() {
// ...
}
// Usage in another file
import { oldFunction } from "./file";
oldFunction(); // <-- Hovering over this will display a deprecation warning
The plugin will display a strikethrough in your editor and provide a tooltip indicating that oldFunction
is deprecated.
The plugin is lightweight and integrates seamlessly with the TypeScript compiler, so it won’t impact performance noticeably, even in large projects.
- Tracking Deprecated Code: Identify deprecated functions, classes, variables, and more in your project and ensure your codebase remains up to date.
- Maintaining Code Quality: Warn developers about deprecated code and encourage the use of newer alternatives.
- Cross-File Detection: Works across multiple files in large codebases, even when deprecated symbols are re-exported or aliased.
Ensure the following:
- The plugin is added to your
tsconfig.json
undercompilerOptions.plugins
. - The symbol is marked with
@deprecated
in a comment right before the declaration.
Warnings about deprecated symbols will appear in the diagnostics view in your IDE (such as VSCode). Hovering over the symbol will display the deprecation message in a tooltip.
If you find this plugin useful, consider supporting its development:
puj |
We welcome contributions to ts-extended-deprecation-plugin
! Please see CONTRIBUTING.md for more details.