Skip to content

fix(eslint-plugin): correct crashes with getTypeArguments for ts < 3.7 #6767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/no-misused-promises.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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