Skip to content

Commit

Permalink
fix(eslint-plugin): [no-throw-literal] fix crash caused by getBaseTyp…
Browse files Browse the repository at this point in the history
…es (#1830)
  • Loading branch information
a-tarasyuk committed Apr 1, 2020
1 parent 188b689 commit 9d53c76
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/eslint-plugin/src/rules/no-throw-literal.ts
Expand Up @@ -43,10 +43,11 @@ export default util.createRule({
}
}

const baseTypes = checker.getBaseTypes(type as ts.InterfaceType);
for (const baseType of baseTypes) {
if (isErrorLike(baseType)) {
return true;
if (symbol.flags & (ts.SymbolFlags.Class | ts.SymbolFlags.Interface)) {
for (const baseType of checker.getBaseTypes(type as ts.InterfaceType)) {
if (isErrorLike(baseType)) {
return true;
}
}
}

Expand Down
31 changes: 31 additions & 0 deletions packages/eslint-plugin/tests/rules/no-throw-literal.test.ts
Expand Up @@ -321,5 +321,36 @@ throw new CustomError();
},
],
},
{
code: `
function foo<T>() {
const res: T;
throw res;
}
`,
errors: [
{
messageId: 'object',
line: 4,
column: 9,
},
],
},
{
code: `
function foo<T>(fn: () => Promise<T>) {
const promise = fn();
const res = promise.then(() => {}).catch(() => {});
throw res;
}
`,
errors: [
{
messageId: 'object',
line: 5,
column: 9,
},
],
},
],
});

0 comments on commit 9d53c76

Please sign in to comment.