Skip to content

Commit

Permalink
fix(eslint-plugin): correct crashes with getTypeArguments for ts < 3.7 (
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Mar 27, 2023
1 parent f5631e9 commit 59eab58
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/no-misused-promises.ts
Expand Up @@ -555,7 +555,7 @@ function voidFunctionArguments(
// Unwrap 'Array<MaybeVoidFunction>' to 'MaybeVoidFunction',
// so that we'll handle it in the same way as a non-rest
// 'param: MaybeVoidFunction'
type = checker.getTypeArguments(type)[0];
type = util.getTypeArguments(type, checker)[0];
for (let i = index; i < node.arguments.length; i++) {
checkThenableOrVoidArgument(
checker,
Expand All @@ -569,7 +569,7 @@ function voidFunctionArguments(
} else if (checker.isTupleType(type)) {
// Check each type in the tuple - for example, [boolean, () => void] would
// add the index of the second tuple parameter to 'voidReturnIndices'
const typeArgs = checker.getTypeArguments(type);
const typeArgs = util.getTypeArguments(type, checker);
for (
let i = index;
i < node.arguments.length && i - index < typeArgs.length;
Expand Down
10 changes: 6 additions & 4 deletions packages/eslint-plugin/src/rules/no-unsafe-argument.ts
Expand Up @@ -57,13 +57,13 @@ class FunctionSignature {
// is a rest param
if (checker.isArrayType(type)) {
restType = {
type: checker.getTypeArguments(type)[0],
type: util.getTypeArguments(type, checker)[0],
kind: RestTypeKind.Array,
index: i,
};
} else if (checker.isTupleType(type)) {
restType = {
typeArguments: checker.getTypeArguments(type),
typeArguments: util.getTypeArguments(type, checker),
kind: RestTypeKind.Tuple,
index: i,
};
Expand Down Expand Up @@ -202,8 +202,10 @@ export default util.createRule<[], MessageIds>({
});
} else if (checker.isTupleType(spreadArgType)) {
// foo(...[tuple1, tuple2])
const spreadTypeArguments =
checker.getTypeArguments(spreadArgType);
const spreadTypeArguments = util.getTypeArguments(
spreadArgType,
checker,
);
for (const tupleType of spreadTypeArguments) {
const parameterType = signature.getNextParameterType();
if (parameterType == null) {
Expand Down
Expand Up @@ -55,7 +55,7 @@ export default util.createRule<Options, MessageIds>({
service.esTreeNodeToTSNodeMap.get(node),
);
if (checker.isArrayType(type) || checker.isTupleType(type)) {
const typeArgs = checker.getTypeArguments(type);
const typeArgs = util.getTypeArguments(type, checker);
return typeArgs.every(
arg => util.getTypeName(checker, arg) === 'string',
);
Expand Down
5 changes: 2 additions & 3 deletions packages/type-utils/src/isTypeReadonly.ts
Expand Up @@ -10,6 +10,7 @@ import {
} from 'tsutils';
import * as ts from 'typescript';

import { getTypeArguments } from './getTypeArguments';
import { getTypeOfPropertyOfType } from './propertyTypes';

const enum Readonlyness {
Expand Down Expand Up @@ -52,9 +53,7 @@ function isTypeReadonlyArrayOrTuple(
function checkTypeArguments(arrayType: ts.TypeReference): Readonlyness {
const typeArguments =
// getTypeArguments was only added in TS3.7
checker.getTypeArguments
? checker.getTypeArguments(arrayType)
: arrayType.typeArguments ?? [];
getTypeArguments(arrayType, checker);

// this shouldn't happen in reality as:
// - tuples require at least 1 type argument
Expand Down

0 comments on commit 59eab58

Please sign in to comment.