Skip to content

fix(deps): update dependency ts-api-utils to v2.1.0 #11003

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/maintenance/Pull_Requests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ If there's no backing issue:
- Thoroughness: does it handle relevant edge cases? Commonly:
- Generics and type parameters (see: `getConstrainedTypeAtLocation`).
- Parenthesis and whitespace (see: `getWrappingFixer`).
- Unions and intersections (see: `unionTypeParts` and `intersectionTypeParts`).
- Unions and intersections (see: `unionConstituents` and `intersectionConstituents`).
- Unit tests:
- All lines are covered per the Codecov / `yarn jest path/to/impacted/file --coverage` report.
- Both "positive" and "negative" ("valid" and "invalid") cases exist, if reasonably possible to test for.
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/await-thenable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default createRule<[], MessageId>({
}

const hasAsyncIteratorSymbol = tsutils
.unionTypeParts(type)
.unionConstituents(type)
.some(
typePart =>
tsutils.getWellKnownSymbolPropertyOfType(
Expand Down Expand Up @@ -137,7 +137,7 @@ export default createRule<[], MessageId>({
}

const hasAsyncDisposeSymbol = tsutils
.unionTypeParts(type)
.unionConstituents(type)
.some(
typePart =>
tsutils.getWellKnownSymbolPropertyOfType(
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/enum-utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getBaseEnumType(typeChecker: ts.TypeChecker, type: ts.Type): ts.Type {
*/
export function getEnumLiterals(type: ts.Type): ts.LiteralType[] {
return tsutils
.unionTypeParts(type)
.unionConstituents(type)
.filter((subType): subType is ts.LiteralType =>
isTypeFlagSet(subType, ts.TypeFlags.EnumLiteral),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ export default createRule<Options, MessageId>({
const returnType = signature.getReturnType();

return tsutils
.unionTypeParts(returnType)
.unionConstituents(returnType)
.some(tsutils.isIntrinsicVoidType);
});
}
Expand All @@ -455,7 +455,7 @@ export default createRule<Options, MessageId>({
const returnType = checker.getTypeFromTypeNode(functionTSNode.type);

return tsutils
.unionTypeParts(returnType)
.unionConstituents(returnType)
.some(tsutils.isIntrinsicVoidType);
}

Expand All @@ -464,7 +464,7 @@ export default createRule<Options, MessageId>({

if (functionType) {
return tsutils
.unionTypeParts(functionType)
.unionConstituents(functionType)
.some(isFunctionReturnTypeIncludesVoid);
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/eslint-plugin/src/rules/no-floating-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ export default createRule<Options, MessageId>({
function isPromiseArray(node: ts.Node): boolean {
const type = checker.getTypeAtLocation(node);
for (const ty of tsutils
.unionTypeParts(type)
.unionConstituents(type)
.map(t => checker.getApparentType(t))) {
if (checker.isArrayType(ty)) {
const arrayType = checker.getTypeArguments(ty)[0];
Expand Down Expand Up @@ -434,7 +434,9 @@ export default createRule<Options, MessageId>({
}

// Otherwise, we always consider the built-in Promise to be Promise-like...
const typeParts = tsutils.unionTypeParts(checker.getApparentType(type));
const typeParts = tsutils.unionConstituents(
checker.getApparentType(type),
);
if (
typeParts.some(typePart =>
isBuiltinSymbolLike(services.program, typePart, 'Promise'),
Expand Down Expand Up @@ -480,7 +482,7 @@ function hasMatchingSignature(
type: ts.Type,
matcher: (signature: ts.Signature) => boolean,
): boolean {
for (const t of tsutils.unionTypeParts(type)) {
for (const t of tsutils.unionConstituents(type)) {
if (t.getCallSignatures().some(matcher)) {
return true;
}
Expand All @@ -497,7 +499,7 @@ function isFunctionParam(
const type: ts.Type | undefined = checker.getApparentType(
checker.getTypeOfSymbolAtLocation(param, node),
);
for (const t of tsutils.unionTypeParts(type)) {
for (const t of tsutils.unionConstituents(type)) {
if (t.getCallSignatures().length !== 0) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default createRule<Options, 'meaninglessVoidOperator' | 'removeVoid'>({
};

const argType = services.getTypeAtLocation(node.argument);
const unionParts = tsutils.unionTypeParts(argType);
const unionParts = tsutils.unionConstituents(argType);
if (
unionParts.every(
part => part.flags & (ts.TypeFlags.Void | ts.TypeFlags.Undefined),
Expand Down
20 changes: 12 additions & 8 deletions packages/eslint-plugin/src/rules/no-misused-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ export default createRule<Options, MessageId>({
function isSometimesThenable(checker: ts.TypeChecker, node: ts.Node): boolean {
const type = checker.getTypeAtLocation(node);

for (const subType of tsutils.unionTypeParts(checker.getApparentType(type))) {
for (const subType of tsutils.unionConstituents(
checker.getApparentType(type),
)) {
if (tsutils.isThenableType(checker, node, subType)) {
return true;
}
Expand All @@ -702,7 +704,9 @@ function isSometimesThenable(checker: ts.TypeChecker, node: ts.Node): boolean {
function isAlwaysThenable(checker: ts.TypeChecker, node: ts.Node): boolean {
const type = checker.getTypeAtLocation(node);

for (const subType of tsutils.unionTypeParts(checker.getApparentType(type))) {
for (const subType of tsutils.unionConstituents(
checker.getApparentType(type),
)) {
const thenProp = subType.getProperty('then');

// If one of the alternates has no then property, it is not thenable in all
Expand All @@ -716,7 +720,7 @@ function isAlwaysThenable(checker: ts.TypeChecker, node: ts.Node): boolean {
// be of the right form to consider it thenable.
const thenType = checker.getTypeOfSymbolAtLocation(thenProp, node);
let hasThenableSignature = false;
for (const subType of tsutils.unionTypeParts(thenType)) {
for (const subType of tsutils.unionConstituents(thenType)) {
for (const signature of subType.getCallSignatures()) {
if (
signature.parameters.length !== 0 &&
Expand Down Expand Up @@ -754,7 +758,7 @@ function isFunctionParam(
const type: ts.Type | undefined = checker.getApparentType(
checker.getTypeOfSymbolAtLocation(param, node),
);
for (const subType of tsutils.unionTypeParts(type)) {
for (const subType of tsutils.unionConstituents(type)) {
if (subType.getCallSignatures().length !== 0) {
return true;
}
Expand Down Expand Up @@ -818,7 +822,7 @@ function voidFunctionArguments(
// We can't use checker.getResolvedSignature because it prefers an early '() => void' over a later '() => Promise<void>'
// See https://github.com/microsoft/TypeScript/issues/48077

for (const subType of tsutils.unionTypeParts(type)) {
for (const subType of tsutils.unionConstituents(type)) {
// Standard function calls and `new` have two different types of signatures
const signatures = ts.isCallExpression(node)
? subType.getCallSignatures()
Expand Down Expand Up @@ -915,7 +919,7 @@ function isThenableReturningFunctionType(
node: ts.Node,
type: ts.Type,
): boolean {
for (const subType of tsutils.unionTypeParts(type)) {
for (const subType of tsutils.unionConstituents(type)) {
if (anySignatureIsThenableType(checker, node, subType)) {
return true;
}
Expand All @@ -934,7 +938,7 @@ function isVoidReturningFunctionType(
): boolean {
let hadVoidReturn = false;

for (const subType of tsutils.unionTypeParts(type)) {
for (const subType of tsutils.unionConstituents(type)) {
for (const signature of subType.getCallSignatures()) {
const returnType = signature.getReturnType();

Expand All @@ -957,7 +961,7 @@ function isVoidReturningFunctionType(
function returnsThenable(checker: ts.TypeChecker, node: ts.Node): boolean {
const type = checker.getApparentType(checker.getTypeAtLocation(node));
return tsutils
.unionTypeParts(type)
.unionConstituents(type)
.some(t => anySignatureIsThenableType(checker, node, t));
}

Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/no-misused-spread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default createRule<Options, MessageIds>({
node: TSESTree.JSXSpreadAttribute | TSESTree.SpreadElement,
type: ts.Type,
): TSESLint.ReportSuggestionArray<MessageIds> | null {
const types = tsutils.unionTypeParts(type);
const types = tsutils.unionConstituents(type);
if (types.some(t => !isMap(services.program, t))) {
return null;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ export default createRule<Options, MessageIds>({

function isIterable(type: ts.Type, checker: ts.TypeChecker): boolean {
return tsutils
.typeParts(type)
.typeConstituents(type)
.some(
t => !!tsutils.getWellKnownSymbolPropertyOfType(t, 'iterator', checker),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function unionTypePartsUnlessBoolean(type: ts.Type): ts.Type[] {
tsutils.isFalseLiteralType(type.types[0]) &&
tsutils.isTrueLiteralType(type.types[1])
? [type]
: tsutils.unionTypeParts(type);
: tsutils.unionConstituents(type);
}

export default createRule({
Expand Down
10 changes: 5 additions & 5 deletions packages/eslint-plugin/src/rules/no-unnecessary-condition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ function isNullishType(type: ts.Type): boolean {
}

function isAlwaysNullish(type: ts.Type): boolean {
return tsutils.unionTypeParts(type).every(isNullishType);
return tsutils.unionConstituents(type).every(isNullishType);
}

/**
* Note that this differs from {@link isNullableType} in that it doesn't consider
* `any` or `unknown` to be nullable.
*/
function isPossiblyNullish(type: ts.Type): boolean {
return tsutils.unionTypeParts(type).some(isNullishType);
return tsutils.unionConstituents(type).some(isNullishType);
}

function toStaticValue(
Expand Down Expand Up @@ -272,14 +272,14 @@ export default createRule<Options, MessageId>({
function nodeIsArrayType(node: TSESTree.Expression): boolean {
const nodeType = getConstrainedTypeAtLocation(services, node);
return tsutils
.unionTypeParts(nodeType)
.unionConstituents(nodeType)
.some(part => checker.isArrayType(part));
}

function nodeIsTupleType(node: TSESTree.Expression): boolean {
const nodeType = getConstrainedTypeAtLocation(services, node);
return tsutils
.unionTypeParts(nodeType)
.unionConstituents(nodeType)
.some(part => checker.isTupleType(part));
}

Expand All @@ -301,7 +301,7 @@ export default createRule<Options, MessageId>({
// `any` or `unknown` or a naked type variable
function isConditionalAlwaysNecessary(type: ts.Type): boolean {
return tsutils
.unionTypeParts(type)
.unionConstituents(type)
.some(
part =>
isTypeAnyType(part) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default createRule<[], MessageId>({
}

function isEnumMemberType(type: ts.Type): boolean {
return tsutils.typeParts(type).some(t => {
return tsutils.typeConstituents(type).some(t => {
const symbol = t.getSymbol();
return !!(
symbol?.valueDeclaration && ts.isEnumMember(symbol.valueDeclaration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ export default createRule<Options, MessageIds>({
)
) {
const uncastParts = tsutils
.unionTypeParts(uncast)
.unionConstituents(uncast)
.filter(part => !isTypeFlagSet(part, ts.TypeFlags.Undefined));

const castParts = tsutils
.unionTypeParts(cast)
.unionConstituents(cast)
.filter(part => !isTypeFlagSet(part, ts.TypeFlags.Undefined));

if (uncastParts.length !== castParts.length) {
Expand Down
8 changes: 4 additions & 4 deletions packages/eslint-plugin/src/rules/no-unsafe-enum-comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function typeViolates(leftTypeParts: ts.Type[], rightType: ts.Type): boolean {
}

function isNumberLike(type: ts.Type): boolean {
const typeParts = tsutils.intersectionTypeParts(type);
const typeParts = tsutils.intersectionConstituents(type);

return typeParts.some(typePart => {
return tsutils.isTypeFlagSet(
Expand All @@ -34,7 +34,7 @@ function isNumberLike(type: ts.Type): boolean {
}

function isStringLike(type: ts.Type): boolean {
const typeParts = tsutils.intersectionTypeParts(type);
const typeParts = tsutils.intersectionConstituents(type);

return typeParts.some(typePart => {
return tsutils.isTypeFlagSet(
Expand Down Expand Up @@ -112,8 +112,8 @@ export default createRule({
// declare const something: Fruit | Vegetable;
// something === Fruit.Apple;
// ```
const leftTypeParts = tsutils.unionTypeParts(leftType);
const rightTypeParts = tsutils.unionTypeParts(rightType);
const leftTypeParts = tsutils.unionConstituents(leftType);
const rightTypeParts = tsutils.unionConstituents(rightType);

// If a type exists in both sides, we consider this comparison safe:
//
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-unsafe-unary-minus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default util.createRule<Options, MessageIds>({
const checker = services.program.getTypeChecker();
if (
tsutils
.unionTypeParts(argType)
.unionConstituents(argType)
.some(
type =>
!tsutils.isTypeFlagSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default createRule({
return undefined;
}

return tsutils.unionTypeParts(type);
return tsutils.unionConstituents(type);
};

const couldBeNullish = (type: ts.Type): boolean => {
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/prefer-find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default createRule({
*/
function isArrayish(type: Type): boolean {
let isAtLeastOneArrayishComponent = false;
for (const unionPart of tsutils.unionTypeParts(type)) {
for (const unionPart of tsutils.unionConstituents(type)) {
if (
tsutils.isIntrinsicNullType(unionPart) ||
tsutils.isIntrinsicUndefinedType(unionPart)
Expand All @@ -125,7 +125,7 @@ export default createRule({
// apparently checker.isArrayType(T[] & S[]) => false.
// so we need to check the intersection parts individually.
const isArrayOrIntersectionThereof = tsutils
.intersectionTypeParts(unionPart)
.intersectionConstituents(unionPart)
.every(
intersectionPart =>
checker.isArrayType(intersectionPart) ||
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ export default createRule<Options, MessageIds>({

if (
tsutils
.typeParts(type)
.typeConstituents(type)
.some(t =>
tsutils
.intersectionTypeParts(t)
.intersectionConstituents(t)
.some(t => tsutils.isTypeFlagSet(t, ignorableFlags)),
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from '@typescript-eslint/utils/ts-eslint';

import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import { unionTypeParts } from 'ts-api-utils';
import { unionConstituents } from 'ts-api-utils';
import * as ts from 'typescript';

import type { ValidOperand } from './gatherLogicalOperands';
Expand Down Expand Up @@ -39,7 +39,7 @@ function includesType(
typeFlagIn: ts.TypeFlags,
): boolean {
const typeFlag = typeFlagIn | ts.TypeFlags.Any | ts.TypeFlags.Unknown;
const types = unionTypeParts(parserServices.getTypeAtLocation(node));
const types = unionConstituents(parserServices.getTypeAtLocation(node));
for (const type of types) {
if (isTypeFlagSet(type, typeFlag)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
} from '@typescript-eslint/utils/ts-eslint';

import { isTypeFlagSet } from '@typescript-eslint/type-utils';
import { unionTypeParts } from 'ts-api-utils';
import { unionConstituents } from 'ts-api-utils';
import * as ts from 'typescript';

import type {
Expand All @@ -29,7 +29,7 @@ export function checkNullishAndReport(
if (
!requireNullish ||
maybeNullishNodes.some(node =>
unionTypeParts(parserServices.getTypeAtLocation(node)).some(t =>
unionConstituents(parserServices.getTypeAtLocation(node)).some(t =>
isTypeFlagSet(t, ts.TypeFlags.Null | ts.TypeFlags.Undefined),
),
)
Expand Down
Loading
Loading