-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
bugSomething isn't workingSomething isn't workinghas prthere is a PR raised to close thisthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin
Description
The recently introduced rule no-throw-literal
(see #1331) does not recognize generic classes as Errors and report false positives.
Repro
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
project: 'tsconfig.json',
},
rules: {
'@typescript-eslint/no-throw-literal': 'error',
},
};
class MyCustomError<Props extends object = {}> extends Error {
constructor(extraProperties?: Props) {
super('Panic!');
Error.captureStackTrace(this, this.constructor);
Object.assign(this, extraProperties);
}
}
throw new MyCustomError();
See https://github.com/bajtos/typescript-eslint-sandbox/blob/master/src/no-throw-literal.ts
Expected Result
No problems are reported.
Actual Result
11:7 error
Expected an error object to be thrown
@typescript-eslint/no-throw-literal
Additional Info
When I remove the generic template argument and make MyCustomError
class a regular class, then the rule works correctly and no error is reported.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
2.15.0 |
@typescript-eslint/parser |
2.15.0 |
TypeScript |
3.7.4 |
ESLint |
6.8.0 |
node |
12.14.0 |
npm |
6.13.4 |
bradzacher
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghas prthere is a PR raised to close thisthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-plugin