eslint-plugin-interface-to-type 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +28 -2
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  # eslint-plugin-interface-to-type
3
3
 
4
- [![npm version](https://img.shields.io/npm/v/eslint-plugin-interface-to-type.svg)](https://www.npmjs.com/package/eslint-plugin-interface-to-type)
5
- [![downloads](https://img.shields.io/npm/dm/eslint-plugin-interface-to-type.svg)](https://www.npmjs.com/package/eslint-plugin-interface-to-type)
4
+ [![npm version](https://img.shields.io/npm/v/eslint-plugin-interface-to-type.svg)](https://www.npmjs.com/package/eslint-plugin-interface-to-type)
5
+ [![downloads](https://img.shields.io/npm/dm/eslint-plugin-interface-to-type.svg)](https://www.npmjs.com/package/eslint-plugin-interface-to-type)
6
6
 
7
7
  An ESLint plugin that enforces the use of `type` aliases instead of `interface` declarations in TypeScript.
8
8
 
@@ -66,6 +66,32 @@ type User = {
66
66
 
67
67
  ---
68
68
 
69
+ ## Why `interface` can be risky
70
+
71
+ One of the reasons to prefer `type` over `interface` is the potential for unexpected behavior with `interface` merging. In TypeScript, when two `interface` declarations share the same name, they are automatically merged into a single declaration. This behavior, known as [Declaration Merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html), can introduce subtle bugs and unintended behaviors in your codebase.
72
+
73
+ ### Example of Declaration Merging
74
+
75
+ ```typescript
76
+ interface User {
77
+ id: number;
78
+ }
79
+
80
+ interface User {
81
+ name: string;
82
+ }
83
+
84
+ // Resulting type
85
+ interface User {
86
+ id: number;
87
+ name: string;
88
+ }
89
+ ```
90
+
91
+ While this behavior can sometimes be useful, it often leads to confusion and makes code harder to maintain, especially in large or collaborative projects. Using `type` avoids this risk entirely, as `type` declarations with the same name will result in a compilation error.
92
+
93
+ ---
94
+
69
95
  ## Autofix
70
96
 
71
97
  This rule supports ESLint's `--fix` option, which can automatically convert `interface` declarations to equivalent `type` aliases.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-interface-to-type",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "mocha tests/**/*.test.js"