From b88cd2332921efcca7ec5f4176f19779346d963b Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Wed, 15 Feb 2023 15:30:59 +1030 Subject: [PATCH] feat: bump ts-api-utils to v0.0.22 (#6472) --- packages/eslint-plugin/package.json | 2 +- packages/eslint-plugin/src/rules/no-unsafe-return.ts | 9 ++++++--- packages/type-utils/package.json | 2 +- packages/type-utils/src/getContextualType.ts | 3 +-- packages/typescript-estree/package.json | 2 +- yarn.lock | 8 ++++---- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 071ba924afe..98d2e756bda 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -53,7 +53,7 @@ "natural-compare-lite": "^1.4.0", "regexpp": "^3.2.0", "semver": "^7.3.7", - "ts-api-utils": "^0.0.21" + "ts-api-utils": "^0.0.22" }, "devDependencies": { "@types/debug": "*", diff --git a/packages/eslint-plugin/src/rules/no-unsafe-return.ts b/packages/eslint-plugin/src/rules/no-unsafe-return.ts index 960f91468c5..c8c2ed9bbbf 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-return.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-return.ts @@ -1,6 +1,7 @@ import type { TSESTree } from '@typescript-eslint/utils'; import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as tools from 'ts-api-utils'; +import * as ts from 'typescript'; import * as util from '../util'; import { getThisExpression } from '../util'; @@ -82,9 +83,11 @@ export default util.createRule({ // so we have to use the contextual typing in these cases, i.e. // const foo1: () => Set = () => new Set(); // the return type of the arrow function is Set even though the variable is typed as Set - let functionType = tools.isExpression(functionTSNode) - ? util.getContextualType(checker, functionTSNode) - : services.getTypeAtLocation(functionNode); + let functionType = + ts.isFunctionExpression(functionTSNode) || + ts.isArrowFunction(functionTSNode) + ? util.getContextualType(checker, functionTSNode) + : services.getTypeAtLocation(functionNode); if (!functionType) { functionType = services.getTypeAtLocation(functionNode); } diff --git a/packages/type-utils/package.json b/packages/type-utils/package.json index 03f44ecf40e..1c71d10e7f7 100644 --- a/packages/type-utils/package.json +++ b/packages/type-utils/package.json @@ -42,7 +42,7 @@ "@typescript-eslint/typescript-estree": "5.52.0", "@typescript-eslint/utils": "5.52.0", "debug": "^4.3.4", - "ts-api-utils": "^0.0.21" + "ts-api-utils": "^0.0.22" }, "devDependencies": { "@typescript-eslint/parser": "5.52.0", diff --git a/packages/type-utils/src/getContextualType.ts b/packages/type-utils/src/getContextualType.ts index 373729ad1dc..e201874b03a 100644 --- a/packages/type-utils/src/getContextualType.ts +++ b/packages/type-utils/src/getContextualType.ts @@ -1,4 +1,3 @@ -import * as tools from 'ts-api-utils'; import * as ts from 'typescript'; /** @@ -23,7 +22,7 @@ export function getContextualType( } else if ( ts.isVariableDeclaration(parent) || ts.isPropertyDeclaration(parent) || - tools.isParameterDeclaration(parent) + ts.isParameter(parent) ) { return parent.type ? checker.getTypeFromTypeNode(parent.type) : undefined; } else if (ts.isJsxExpression(parent)) { diff --git a/packages/typescript-estree/package.json b/packages/typescript-estree/package.json index ac143653382..b393b1b8add 100644 --- a/packages/typescript-estree/package.json +++ b/packages/typescript-estree/package.json @@ -48,7 +48,7 @@ "globby": "^11.1.0", "is-glob": "^4.0.3", "semver": "^7.3.7", - "ts-api-utils": "^0.0.21" + "ts-api-utils": "^0.0.22" }, "devDependencies": { "@babel/code-frame": "*", diff --git a/yarn.lock b/yarn.lock index 013601dd9cc..6e6eb02b37d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13714,10 +13714,10 @@ trough@^1.0.0: resolved "https://registry.yarnpkg.com/trough/-/trough-1.0.5.tgz#b8b639cefad7d0bb2abd37d433ff8293efa5f406" integrity sha512-rvuRbTarPXmMb79SmzEp8aqXNKcK+y0XaB298IXueQ8I2PsrATcPBCSPyK/dDNa2iWOhKlfNnOjdAOTBU/nkFA== -ts-api-utils@^0.0.21: - version "0.0.21" - resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-0.0.21.tgz#d5e58e3200f848123a89f3987d6ee9b613642d01" - integrity sha512-Dr9RHp5+4jLF+2wARhwQO1Z/6BFVsKigZhascnbsbyzSEDKO9qGlN7RgsquqHwP0lHiQmLJFYiGCLXTmcDC9Wg== +ts-api-utils@^0.0.22: + version "0.0.22" + resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-0.0.22.tgz#c58aac346f3990e6e164b4907aca57f54d81a2e8" + integrity sha512-XrQNMP/CQk2gOa+NfNIxNSf60n+RsC7tAkyCxhwnkShxUFpitvwNDfDxdMIZxHtdKKqqeRi94T191sNN7pFSrg== ts-essentials@^2.0.3: version "2.0.12"