From 015a3bf2251279524854bef777811a66fdf6d586 Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Thu, 12 Nov 2020 14:32:52 +0100 Subject: [PATCH 1/3] feat(eslint-plugin): add reference on how to type an empty object in `ban-types` --- packages/eslint-plugin/docs/rules/ban-types.md | 1 + packages/eslint-plugin/src/rules/ban-types.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md index 761cac128f37..b8edb2a28bfe 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 [microsoft/TypeScript#2063](https://github.com/typescript-eslint/typescript-eslint/issues/2063). - 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 0187134e9917..13d4ce2a44f7 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -93,6 +93,9 @@ 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 "an empty object", you probably want to use the following instead:', + ' type NoElements = { [P in keyof T]: never };', + ' type EmptyObject = NoElements>;', ].join('\n'), }, object: { From 2e4da9a7764ba0d53eedb52b39863f9e6f1a2522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Martin?= Date: Mon, 16 Nov 2020 23:42:33 +0100 Subject: [PATCH 2/3] Update packages/eslint-plugin/docs/rules/ban-types.md Co-authored-by: Brad Zacher --- packages/eslint-plugin/docs/rules/ban-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/docs/rules/ban-types.md b/packages/eslint-plugin/docs/rules/ban-types.md index b8edb2a28bfe..bf59ffb84618 100644 --- a/packages/eslint-plugin/docs/rules/ban-types.md +++ b/packages/eslint-plugin/docs/rules/ban-types.md @@ -74,7 +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 [microsoft/TypeScript#2063](https://github.com/typescript-eslint/typescript-eslint/issues/2063). + - 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). From 02f02f65787a72fcd26956528f2a6ae1e7edc730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Martin?= Date: Mon, 16 Nov 2020 23:43:29 +0100 Subject: [PATCH 3/3] Update packages/eslint-plugin/src/rules/ban-types.ts Co-authored-by: Brad Zacher --- packages/eslint-plugin/src/rules/ban-types.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index 13d4ce2a44f7..c9f03c89b969 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -93,9 +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 "an empty object", you probably want to use the following instead:', - ' type NoElements = { [P in keyof T]: never };', - ' type EmptyObject = NoElements>;', + '- If you want a type meaning "empty object", you probably want `Record` instead.', ].join('\n'), }, object: {