8000 fix(eslint-plugin): [no-redundant-type-constituents] differentiate a … · jakebailey/typescript-eslint@8087d17 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 8087d17

Browse files
authored
fix(eslint-plugin): [no-redundant-type-constituents] differentiate a types-error any from a true any (typescript-eslint#9555)
* fix: support error type * fix: error message * fix: intersection error message
1 parent 8e01254 commit 8087d17

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

packages/eslint-plugin/src/rules/no-redundant-type-constituents.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ function describeLiteralType(type: ts.Type): string {
102102
return type.value.toString();
103103
}
104104

105+
if (tsutils.isIntrinsicErrorType(type) && type.aliasSymbol) {
106+
return type.aliasSymbol.escapedName.toString();
107+
}
108+
105109
if (isTypeAnyType(type)) {
106110
return 'any';
107111
}
@@ -201,6 +205,7 @@ export default createRule({
201205
primitiveOverridden: `{{primitive}} is overridden by the {{literal}} in this intersection type.`,
202206
overridden: `'{{typeName}}' is overridden by other types in this {{container}} type.`,
203207
overrides: `'{{typeName}}' overrides all other types in this {{container}} type.`,
208+
errorTypeOverrides: `'{{typeName}}' is an 'error' type that acts as 'any' and overrides all other types in this {{container}} type.`,
204209
},
205210
schema: [],
206211
type: 'suggestion',
@@ -292,7 +297,10 @@ export default createRule({
292297
container: 'intersection',
293298
typeName,
294299
},
295-
messageId,
300+
messageId:
301+
typeFlags === ts.TypeFlags.Any && typeName !== 'any'
302+
? 'errorTypeOverrides'
303+
: messageId,
296304
node: typeNode,
297305
});
298306
return true;
@@ -419,7 +427,10 @@ export default createRule({
419427
container: 'union',
420428
typeName,
421429
},
422-
messageId: 'overrides',
430+
messageId:
431+
typeFlags === ts.TypeFlags.Any && typeName !== 'any'
432+
? 'errorTypeOverrides'
433+
: 'overrides',
423434
node: typeNode,
424435
});
425436
return true;

packages/eslint-plugin/tests/rules/no-redundant-type-constituents.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,19 @@ ruleTester.run('no-redundant-type-constituents', rule, {
310310
},
311311
],
312312
},
313+
{
314+
code: 'type ErrorTypes = NotKnown | 0;',
315+
errors: [
316+
{
317+
column: 19,
318+
data: {
319+
container: 'union',
320+
typeName: 'NotKnown',
321+
},
322+
messageId: 'errorTypeOverrides',
323+
},
324+
],
325+
},
313326
{
314327
code: 'type T = number | 0;',
315328
errors: [
@@ -653,6 +666,19 @@ ruleTester.run('no-redundant-type-constituents', rule, {
653666
},
654667
],
655668 },
669+
{
670+
code: 'type ErrorTypes = NotKnown & 0;',
671+
errors: [
672+
{
673+
column: 19,
674+
data: {
675+
container: 'intersection',
676+
typeName: 'NotKnown',
677+
},
678+
messageId: 'errorTypeOverrides',
679+
},
680+
],
681+
},
656682
{
657683
code: 'type T = number & never;',
658684
errors: [

0 commit comments

Comments
 (0)
0