Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab60541

Browse files
MichaelDeBoeybradzacher
authored andcommitted
feat(eslint-plugin): remove object from ban-types' default types (typescript-eslint#3818)
BREAKING CHANGE: `ban-types` no longer reports `object` by default
1 parent 80e2237 commit ab60541

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

packages/eslint-plugin/docs/rules/ban-types.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ The default options provide a set of "best practices", intended to provide safet
7575
- Avoid the `Object` and `{}` types, as they mean "any non-nullish value".
7676
- This is a point of confusion for many developers, who think it means "any object type".
7777
- See [this comment for more information](https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492).
78-
- Avoid the `object` type, as it is currently hard to use due to not being able to assert that keys exist.
79-
- See [microsoft/TypeScript#21732](https://github.com/microsoft/TypeScript/issues/21732).
8078

8179
**_Important note:_** the default options suggest using `Record<string, unknown>`; this was a stylistic decision, as the built-in `Record` type is considered to look cleaner.
8280

@@ -126,12 +124,6 @@ const defaultTypes = {
126124
'- If you want a type meaning "any value", you probably want `unknown` instead.',
127125
].join('\n'),
128126
},
129-
object: {
130-
message: [
131-
'The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).',
132-
'Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys.',
133-
].join('\n'),
134-
},
135127
};
136128
```
137129

@@ -152,8 +144,6 @@ const symb: Symbol = Symbol('foo');
152144
const func: Function = () => 1;
153145

154146
// use safer object types
155-
const lowerObj: object = {};
156-
157147
const capitalObj1: Object = 1;
158148
const capitalObj2: Object = { a: 'string' };
159149

@@ -174,7 +164,7 @@ const symb: symbol = Symbol('foo');
174164
const func: () => number = () => 1;
175165

176166
// use safer object types
177-
const lowerObj: Record<string, unknown> = {};
167+
const lowerObj: object = {};
178168

179169
const capitalObj1: number = 1;
180170
const capitalObj2: { a: string } = { a: 'string' };
@@ -185,4 +175,4 @@ const curly2: Record<'a', string> = { a: 'string' };
185175

186176
## Compatibility
187177

188-
- TSLint: [ban-types](https://palantir.github.io/tslint/rules/ban-types/)
178+
- TSLint: [ban-types](https://palantir.github.io/tslint/rules/ban-types)

packages/eslint-plugin/src/rules/ban-types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ const defaultTypes: Types = {
9696
'- If you want a type meaning "empty object", you probably want `Record<string, never>` instead.',
9797
].join('\n'),
9898
},
99-
object: {
100-
message: [
101-
'The `object` type is currently hard to use ([see this issue](https://github.com/microsoft/TypeScript/issues/21732)).',
102-
'Consider using `Record<string, unknown>` instead, as it allows you to more easily inspect and use the keys.',
103-
].join('\n'),
104-
},
10599
};
106100

107101
export const TYPE_KEYWORDS = {

0 commit comments

Comments
 (0)