@typescript-eslint/type-utils 8.26.1-alpha.4 → 8.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ import type * as ts from 'typescript';
2
+ export declare enum AnyType {
3
+ Any = 0,
4
+ PromiseAny = 1,
5
+ AnyArray = 2,
6
+ Safe = 3
7
+ }
8
+ /**
9
+ * @returns `AnyType.Any` if the type is `any`, `AnyType.AnyArray` if the type is `any[]` or `readonly any[]`, `AnyType.PromiseAny` if the type is `Promise<any>`,
10
+ * otherwise it returns `AnyType.Safe`.
11
+ */
12
+ export declare function discriminateAnyType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program, tsNode: ts.Node): AnyType;
13
+ //# sourceMappingURL=discriminateAnyType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discriminateAnyType.d.ts","sourceRoot":"","sources":["../src/discriminateAnyType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAMtC,oBAAY,OAAO;IACjB,GAAG,IAAA;IACH,UAAU,IAAA;IACV,QAAQ,IAAA;IACR,IAAI,IAAA;CACL;AACD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,EACvB,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,MAAM,EAAE,EAAE,CAAC,IAAI,GACd,OAAO,CAET"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.AnyType = void 0;
37
+ exports.discriminateAnyType = discriminateAnyType;
38
+ const tsutils = __importStar(require("ts-api-utils"));
39
+ const predicates_1 = require("./predicates");
40
+ var AnyType;
41
+ (function (AnyType) {
42
+ AnyType[AnyType["Any"] = 0] = "Any";
43
+ AnyType[AnyType["PromiseAny"] = 1] = "PromiseAny";
44
+ AnyType[AnyType["AnyArray"] = 2] = "AnyArray";
45
+ AnyType[AnyType["Safe"] = 3] = "Safe";
46
+ })(AnyType || (exports.AnyType = AnyType = {}));
47
+ /**
48
+ * @returns `AnyType.Any` if the type is `any`, `AnyType.AnyArray` if the type is `any[]` or `readonly any[]`, `AnyType.PromiseAny` if the type is `Promise<any>`,
49
+ * otherwise it returns `AnyType.Safe`.
50
+ */
51
+ function discriminateAnyType(type, checker, program, tsNode) {
52
+ return discriminateAnyTypeWorker(type, checker, program, tsNode, new Set());
53
+ }
54
+ function discriminateAnyTypeWorker(type, checker, program, tsNode, visited) {
55
+ if (visited.has(type)) {
56
+ return AnyType.Safe;
57
+ }
58
+ visited.add(type);
59
+ if ((0, predicates_1.isTypeAnyType)(type)) {
60
+ return AnyType.Any;
61
+ }
62
+ if ((0, predicates_1.isTypeAnyArrayType)(type, checker)) {
63
+ return AnyType.AnyArray;
64
+ }
65
+ for (const part of tsutils.typeParts(type)) {
66
+ if (tsutils.isThenableType(checker, tsNode, part)) {
67
+ const awaitedType = checker.getAwaitedType(part);
68
+ if (awaitedType) {
69
+ const awaitedAnyType = discriminateAnyTypeWorker(awaitedType, checker, program, tsNode, visited);
70
+ if (awaitedAnyType === AnyType.Any) {
71
+ return AnyType.PromiseAny;
72
+ }
73
+ }
74
+ }
75
+ }
76
+ return AnyType.Safe;
77
+ }
package/dist/index.d.ts CHANGED
@@ -13,5 +13,6 @@ export * from './propertyTypes';
13
13
  export * from './requiresQuoting';
14
14
  export * from './typeFlagUtils';
15
15
  export * from './TypeOrValueSpecifier';
16
+ export * from './discriminateAnyType';
16
17
  export { getDecorators, getModifiers, typescriptVersionIsAtLeast, } from '@typescript-eslint/typescript-estree';
17
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,0BAA0B,GAC3B,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,0BAA0B,GAC3B,MAAM,sCAAsC,CAAC"}
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ __exportStar(require("./propertyTypes"), exports);
30
30
  __exportStar(require("./requiresQuoting"), exports);
31
31
  __exportStar(require("./typeFlagUtils"), exports);
32
32
  __exportStar(require("./TypeOrValueSpecifier"), exports);
33
+ __exportStar(require("./discriminateAnyType"), exports);
33
34
  var typescript_estree_1 = require("@typescript-eslint/typescript-estree");
34
35
  Object.defineProperty(exports, "getDecorators", { enumerable: true, get: function () { return typescript_estree_1.getDecorators; } });
35
36
  Object.defineProperty(exports, "getModifiers", { enumerable: true, get: function () { return typescript_estree_1.getModifiers; } });
@@ -29,17 +29,6 @@ export declare function isTypeAnyArrayType(type: ts.Type, checker: ts.TypeChecke
29
29
  * @returns true if the type is `unknown[]`
30
30
  */
31
31
  export declare function isTypeUnknownArrayType(type: ts.Type, checker: ts.TypeChecker): boolean;
32
- export declare enum AnyType {
33
- Any = 0,
34
- PromiseAny = 1,
35
- AnyArray = 2,
36
- Safe = 3
37
- }
38
- /**
39
- * @returns `AnyType.Any` if the type is `any`, `AnyType.AnyArray` if the type is `any[]` or `readonly any[]`, `AnyType.PromiseAny` if the type is `Promise<any>`,
40
- * otherwise it returns `AnyType.Safe`.
41
- */
42
- export declare function discriminateAnyType(type: ts.Type, checker: ts.TypeChecker, program: ts.Program, tsNode: ts.Node): AnyType;
43
32
  /**
44
33
  * @returns Whether a type is an instance of the parent type, including for the parent's base types.
45
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAMjC;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CASrD;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,OAAO,CAQT;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAEtD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAExD;AAYD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,aAAa,CAM3E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG,OAAO,CAQpD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,OAAO,CAKT;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,OAAO,CAKT;AAED,oBAAY,OAAO;IACjB,GAAG,IAAA;IACH,UAAU,IAAA;IACV,QAAQ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OAAO,CAQpD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,OAAO,CAKT;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,OAAO,EAAE,EAAE,CAAC,WAAW,GACtB,OAAO,CAKT;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,UAAU,EAAE,EAAE,CAAC,IAAI,GAClB,OAAO,CAqBT;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,EAAE,CAAC,IAAI,GACZ,IAAI,IAAI,EAAE,CAAC,iBAAiB,CAE9B;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,EAAE,CAAC,IAAI,GACZ,IAAI,IAAI,EAAE,CAAC,mBAAmB,CAEhC"}
@@ -36,7 +36,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.AnyType = void 0;
40
39
  exports.isNullableType = isNullableType;
41
40
  exports.isTypeArrayTypeOrUnionOfArrayTypes = isTypeArrayTypeOrUnionOfArrayTypes;
42
41
  exports.isTypeNeverType = isTypeNeverType;
@@ -45,7 +44,6 @@ exports.isTypeReferenceType = isTypeReferenceType;
45
44
  exports.isTypeAnyType = isTypeAnyType;
46
45
  exports.isTypeAnyArrayType = isTypeAnyArrayType;
47
46
  exports.isTypeUnknownArrayType = isTypeUnknownArrayType;
48
- exports.discriminateAnyType = discriminateAnyType;
49
47
  exports.typeIsOrHasBaseType = typeIsOrHasBaseType;
50
48
  exports.isTypeBigIntLiteralType = isTypeBigIntLiteralType;
51
49
  exports.isTypeTemplateLiteralType = isTypeTemplateLiteralType;
@@ -130,37 +128,6 @@ function isTypeUnknownArrayType(type, checker) {
130
128
  return (checker.isArrayType(type) &&
131
129
  isTypeUnknownType(checker.getTypeArguments(type)[0]));
132
130
  }
133
- var AnyType;
134
- (function (AnyType) {
135
- AnyType[AnyType["Any"] = 0] = "Any";
136
- AnyType[AnyType["PromiseAny"] = 1] = "PromiseAny";
137
- AnyType[AnyType["AnyArray"] = 2] = "AnyArray";
138
- AnyType[AnyType["Safe"] = 3] = "Safe";
139
- })(AnyType || (exports.AnyType = AnyType = {}));
140
- /**
141
- * @returns `AnyType.Any` if the type is `any`, `AnyType.AnyArray` if the type is `any[]` or `readonly any[]`, `AnyType.PromiseAny` if the type is `Promise<any>`,
142
- * otherwise it returns `AnyType.Safe`.
143
- */
144
- function discriminateAnyType(type, checker, program, tsNode) {
145
- if (isTypeAnyType(type)) {
146
- return AnyType.Any;
147
- }
148
- if (isTypeAnyArrayType(type, checker)) {
149
- return AnyType.AnyArray;
150
- }
151
- for (const part of tsutils.typeParts(type)) {
152
- if (tsutils.isThenableType(checker, tsNode, part)) {
153
- const awaitedType = checker.getAwaitedType(part);
154
- if (awaitedType) {
155
- const awaitedAnyType = discriminateAnyType(awaitedType, checker, program, tsNode);
156
- if (awaitedAnyType === AnyType.Any) {
157
- return AnyType.PromiseAny;
158
- }
159
- }
160
- }
161
- }
162
- return AnyType.Safe;
163
- }
164
131
  /**
165
132
  * @returns Whether a type is an instance of the parent type, including for the parent's base types.
166
133
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/type-utils",
3
- "version": "8.26.1-alpha.4",
3
+ "version": "8.26.1",
4
4
  "description": "Type utilities for working with TypeScript + ESLint together",
5
5
  "files": [
6
6
  "dist",
@@ -47,8 +47,8 @@
47
47
  "check-types": "npx nx typecheck"
48
48
  },
49
49
  "dependencies": {
50
- "@typescript-eslint/typescript-estree": "8.26.1-alpha.4",
51
- "@typescript-eslint/utils": "8.26.1-alpha.4",
50
+ "@typescript-eslint/typescript-estree": "8.26.1",
51
+ "@typescript-eslint/utils": "8.26.1",
52
52
  "debug": "^4.3.4",
53
53
  "ts-api-utils": "^2.0.1"
54
54
  },
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@jest/types": "29.6.3",
61
- "@typescript-eslint/parser": "8.26.1-alpha.4",
61
+ "@typescript-eslint/parser": "8.26.1",
62
62
  "ajv": "^6.12.6",
63
63
  "downlevel-dts": "*",
64
64
  "jest": "29.7.0",