diff --git a/lib/utils/ts-utils/ts-ast.js b/lib/utils/ts-utils/ts-ast.js index e9977e3bd..4e698aa40 100644 --- a/lib/utils/ts-utils/ts-ast.js +++ b/lib/utils/ts-utils/ts-ast.js @@ -14,6 +14,8 @@ const { inferRuntimeTypeFromTypeNode } = require('./ts-types') * @typedef {import('../index').ComponentTypeEmit} ComponentTypeEmit */ +const noop = Function.prototype + module.exports = { isTypeNode, flattenTypeNodes, @@ -25,17 +27,21 @@ module.exports = { } /** - * @param {TSESTreeNode | ASTNode} node - * @returns {node is TSESTreeTypeNode} + * @param {ASTNode} node + * @returns {node is TypeNode} */ function isTypeNode(node) { - return ( + if ( + node.type === 'TSAbstractKeyword' || node.type === 'TSAnyKeyword' || + node.type === 'TSAsyncKeyword' || node.type === 'TSArrayType' || node.type === 'TSBigIntKeyword' || node.type === 'TSBooleanKeyword' || node.type === 'TSConditionalType' || node.type === 'TSConstructorType' || + node.type === 'TSDeclareKeyword' || + node.type === 'TSExportKeyword' || node.type === 'TSFunctionType' || node.type === 'TSImportType' || node.type === 'TSIndexedAccessType' || @@ -50,7 +56,13 @@ function isTypeNode(node) { node.type === 'TSNumberKeyword' || node.type === 'TSObjectKeyword' || node.type === 'TSOptionalType' || + node.type === 'TSQualifiedName' || + node.type === 'TSPrivateKeyword' || + node.type === 'TSProtectedKeyword' || + node.type === 'TSPublicKeyword' || + node.type === 'TSReadonlyKeyword' || node.type === 'TSRestType' || + node.type === 'TSStaticKeyword' || node.type === 'TSStringKeyword' || node.type === 'TSSymbolKeyword' || node.type === 'TSTemplateLiteralType' || @@ -65,7 +77,16 @@ function isTypeNode(node) { node.type === 'TSUnionType' || node.type === 'TSUnknownKeyword' || node.type === 'TSVoidKeyword' - ) + ) { + /** @type {TypeNode['type']} for type check */ + const type = node.type + noop(type) + return true + } + /** @type {Exclude} for type check */ + const type = node.type + noop(type) + return false } /** diff --git a/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts b/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts index 0fa6d68b0..e3c5f0faf 100644 --- a/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts +++ b/typings/eslint-plugin-vue/util-types/ast/ts-ast.ts @@ -92,12 +92,11 @@ export interface TSFunctionType extends TSFunctionSignatureBase { type: 'TSFunctionType' } +type TypeNodeTypes = `${TSESTree.TypeNode['type']}` + export type TypeNode = | (HasParentNode & { - type: Exclude< - TSESTree.TypeNode['type'], - 'TSFunctionType' | 'TSLiteralType' - > + type: Exclude }) | TSFunctionType | TSLiteralType