From 3c1c5247035112191d5a489256a3aa903c392147 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 2 Feb 2022 17:35:20 -0500 Subject: [PATCH] chore: more test coverage; I'd missed a couple of keywords --- .../rules/no-redundant-type-constituents.ts | 2 + .../no-redundant-type-constituents.test.ts | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts b/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts index 48a7c02499f..4a75cf2214e 100644 --- a/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts +++ b/packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts @@ -44,6 +44,8 @@ const keywordNodeTypesToTsTypes = new Map([ [TSESTree.AST_NODE_TYPES.TSAnyKeyword, ts.TypeFlags.Any], [TSESTree.AST_NODE_TYPES.TSBigIntKeyword, ts.TypeFlags.BigInt], [TSESTree.AST_NODE_TYPES.TSBooleanKeyword, ts.TypeFlags.Boolean], + [TSESTree.AST_NODE_TYPES.TSNeverKeyword, ts.TypeFlags.Never], + [TSESTree.AST_NODE_TYPES.TSUnknownKeyword, ts.TypeFlags.Unknown], [TSESTree.AST_NODE_TYPES.TSNumberKeyword, ts.TypeFlags.Number], [TSESTree.AST_NODE_TYPES.TSStringKeyword, ts.TypeFlags.String], ]); diff --git a/packages/eslint-plugin/tests/rules/no-redundant-type-constituents.test.ts b/packages/eslint-plugin/tests/rules/no-redundant-type-constituents.test.ts index f6fb288865d..68baac588ff 100644 --- a/packages/eslint-plugin/tests/rules/no-redundant-type-constituents.test.ts +++ b/packages/eslint-plugin/tests/rules/no-redundant-type-constituents.test.ts @@ -13,8 +13,19 @@ const ruleTester = new RuleTester({ ruleTester.run('no-redundant-type-constituents', rule, { valid: [ - 'type T = any;', - 'type T = never;', + ` + type T = any; + type U = T; + `, + ` + type T = never; + type U = T; + `, + ` + type T = 1 | 2; + type U = T | 3; + type V = U; + `, 'type T = () => never;', 'type T = () => never | string;', ` @@ -36,7 +47,6 @@ ruleTester.run('no-redundant-type-constituents', rule, { type B = never; type T = { new (): string | B }; `, - 'type T = unknown;', ` type B = unknown; type T = B; @@ -134,6 +144,11 @@ ruleTester.run('no-redundant-type-constituents', rule, { type B = string; type T = B & null; `, + 'type T = `${string}` & null;', + ` + type B = \`\${string}\`; + type T = B & null; + `, ], invalid: [ @@ -224,6 +239,22 @@ ruleTester.run('no-redundant-type-constituents', rule, { }, ], }, + { + code: ` + type B = never; + type T = B | number; + `, + errors: [ + { + column: 18, + data: { + container: 'union', + typeName: 'never', + }, + messageId: 'overridden', + }, + ], + }, { code: 'type T = never | number;', errors: [