@typescript-eslint/eslint-plugin 8.72.2-alpha.9 → 8.72.3-alpha.0
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.
|
@@ -182,6 +182,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
182
182
|
if (((0, util_1.isTypeFlagSet)(uncast, ts.TypeFlags.NonPrimitive) &&
|
|
183
183
|
!(0, util_1.isTypeFlagSet)(cast, ts.TypeFlags.NonPrimitive)) ||
|
|
184
184
|
hasIndexSignature(uncast) !== hasIndexSignature(cast) ||
|
|
185
|
+
isNumberToEnumAssertion(uncast, cast) ||
|
|
185
186
|
containsAny(uncast) ||
|
|
186
187
|
containsAny(cast) ||
|
|
187
188
|
(containsTypeVariable(cast) && !containsTypeVariable(uncast))) {
|
|
@@ -225,6 +226,24 @@ exports.default = (0, util_1.createRule)({
|
|
|
225
226
|
.unionConstituents(type)
|
|
226
227
|
.some(part => checker.getIndexInfosOfType(part).length > 0);
|
|
227
228
|
}
|
|
229
|
+
// `number` and a numeric enum are assignable to each other, so they count
|
|
230
|
+
// as mutually assignable even though the assertion changes the type:
|
|
231
|
+
// `values[+key as Color]` compiles where `values[+key]` does not.
|
|
232
|
+
function isNumberToEnumAssertion(uncast, cast) {
|
|
233
|
+
return ((hasEnumConstituent(cast) && hasPlainNumberConstituent(uncast)) ||
|
|
234
|
+
(hasEnumConstituent(uncast) && hasPlainNumberConstituent(cast)));
|
|
235
|
+
}
|
|
236
|
+
function hasEnumConstituent(type) {
|
|
237
|
+
return tsutils
|
|
238
|
+
.unionConstituents(type)
|
|
239
|
+
.some(part => (0, util_1.isTypeFlagSet)(part, ts.TypeFlags.EnumLike));
|
|
240
|
+
}
|
|
241
|
+
function hasPlainNumberConstituent(type) {
|
|
242
|
+
return tsutils
|
|
243
|
+
.unionConstituents(type)
|
|
244
|
+
.some(part => (0, util_1.isTypeFlagSet)(part, ts.TypeFlags.NumberLike) &&
|
|
245
|
+
!(0, util_1.isTypeFlagSet)(part, ts.TypeFlags.EnumLike));
|
|
246
|
+
}
|
|
228
247
|
function getTypeArguments(type) {
|
|
229
248
|
return (type.aliasTypeArguments ??
|
|
230
249
|
(tsutils.isTypeReference(type) ? checker.getTypeArguments(type) : []));
|
|
@@ -149,6 +149,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
149
149
|
create(context, [{ allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing, ignoreBooleanCoercion, ignoreConditionalTests, ignoreIfStatements, ignoreMixedLogicalExpressions, ignorePrimitives, ignoreTernaryTests, },]) {
|
|
150
150
|
const parserServices = (0, util_1.getParserServices)(context);
|
|
151
151
|
const compilerOptions = parserServices.program.getCompilerOptions();
|
|
152
|
+
const checker = parserServices.program.getTypeChecker();
|
|
152
153
|
const isStrictNullChecks = tsutils.isStrictCompilerOptionEnabled(compilerOptions, 'strictNullChecks');
|
|
153
154
|
if (!isStrictNullChecks &&
|
|
154
155
|
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing !== true) {
|
|
@@ -329,7 +330,19 @@ exports.default = (0, util_1.createRule)({
|
|
|
329
330
|
return true;
|
|
330
331
|
}
|
|
331
332
|
const type = parserServices.getTypeAtLocation(nullishCoalescingLeftNode);
|
|
332
|
-
|
|
333
|
+
let flags = (0, util_1.getTypeFlags)(type);
|
|
334
|
+
for (const part of tsutils.unionConstituents(type)) {
|
|
335
|
+
// a generic type (`T`, `NoInfer<T>`, `T[K]`, ...) may be `null` or
|
|
336
|
+
// `undefined` unless its constraint rules that out
|
|
337
|
+
if (!tsutils.isTypeFlagSet(part, ts.TypeFlags.Instantiable)) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
const constraintType = checker.getBaseConstraintOfType(part);
|
|
341
|
+
if (constraintType == null) {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
flags |= (0, util_1.getTypeFlags)(constraintType);
|
|
345
|
+
}
|
|
333
346
|
if (flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown)) {
|
|
334
347
|
return false;
|
|
335
348
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "8.72.
|
|
3
|
+
"version": "8.72.3-alpha.0",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@eslint-community/regexpp": "^4.12.2",
|
|
50
|
-
"@typescript-eslint/scope-manager": "8.72.
|
|
51
|
-
"@typescript-eslint/type-utils": "8.72.
|
|
52
|
-
"@typescript-eslint/utils": "8.72.
|
|
53
|
-
"@typescript-eslint/visitor-keys": "8.72.
|
|
50
|
+
"@typescript-eslint/scope-manager": "8.72.3-alpha.0",
|
|
51
|
+
"@typescript-eslint/type-utils": "8.72.3-alpha.0",
|
|
52
|
+
"@typescript-eslint/utils": "8.72.3-alpha.0",
|
|
53
|
+
"@typescript-eslint/visitor-keys": "8.72.3-alpha.0",
|
|
54
54
|
"ignore": "^7.0.5",
|
|
55
55
|
"natural-compare": "^1.4.0",
|
|
56
56
|
"ts-api-utils": "^2.5.0"
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@types/mdast": "^4.0.4",
|
|
61
61
|
"@types/natural-compare": "^1.4.3",
|
|
62
62
|
"@types/react": "^18.3.21",
|
|
63
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.72.
|
|
64
|
-
"@typescript-eslint/rule-tester": "8.72.
|
|
63
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.72.3-alpha.0",
|
|
64
|
+
"@typescript-eslint/rule-tester": "8.72.3-alpha.0",
|
|
65
65
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
66
66
|
"@vitest/coverage-v8": "^5.0.3",
|
|
67
67
|
"ajv": "^6.12.6",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"vitest": "^5.0.3"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@typescript-eslint/parser": "^8.72.
|
|
84
|
+
"@typescript-eslint/parser": "^8.72.3-alpha.0",
|
|
85
85
|
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
|
|
86
86
|
"typescript": ">=4.8.4 <6.1.0"
|
|
87
87
|
},
|