From 7af66a73dfd89196f4c7fa4dd80b2b410a8bb97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Martin?= Date: Tue, 17 Nov 2020 19:18:31 +0100 Subject: [PATCH] docs(eslint-plugin): [ban-types] add reference on how to type an empty object (#2758) --- packages/eslint-plugin/docs/rules/ban-types.md | 1 + packages/eslint-plugin/src/rules/ban-types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md index 761cac128f3..bf59ffb8461 100644 --- a/packages/eslint-plugin/docs/rules/ban-types.md +++ b/packages/eslint-plugin/docs/rules/ban-types.md @@ -74,6 +74,7 @@ The default options provide a set of "best practices", intended to provide safet - It accepts class declarations, which will fail when called, as they are called without the `new` keyword. - Avoid the `Object` and `{}` types, as they mean "any non-nullish value". - This is a point of confusion for many developers, who think it means "any object type". + - See [this comment for more information](https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492). - Avoid the `object` type, as it is currently hard to use due to not being able to assert that keys exist. - See [microsoft/TypeScript#21732](https://github.com/microsoft/TypeScript/issues/21732). diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 0187134e991..c9f03c89b96 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -93,6 +93,7 @@ const defaultTypes: Types = { '`{}` actually means "any non-nullish value".', '- If you want a type meaning "any object", you probably want `Record` instead.', '- If you want a type meaning "any value", you probably want `unknown` instead.', + '- If you want a type meaning "empty object", you probably want `Record` instead.', ].join('\n'), }, object: {