SyntaxError: Syntax error in selector при использовании (:not) и (:has)

Сообщение об ошибке:

SyntaxError: Syntax error in selector ":not(TSTypeAliasDeclaration:has(> Identifier[name=Nullable])):has(> TSUnionType:has(> TSNullKeyword):not(:has(> TSUndefinedKeyword)))" at position 32: Expected " ", "!", "#", "*", ".", ":", ":first-child", ":has(", ":last-child", ":matches(", ":not(", ":nth-child(", ":nth-last-child(", "[", or [^ [\],():#!=><~+.] but ">" found.

package.json (урезанный):

{
    "devDependencies": {
        "eslint": "^9.26.0",
        "typescript": "^5.5.4",
        "typescript-eslint": "^8.33.1",
    },
}

.eslintrc:

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "rules": {
    "no-restricted-syntax": [
      "error",
      {
        "selector": ":not(TSTypeAliasDeclaration:has(> Identifier[name=Nullable])):has(> TSUnionType:has( > TSNullKeyword):not(:has(> TSUndefinedKeyword)))",
        "message": "Use `Nullable<T>` utility type instead of `| null`."
      },
      {
        "selector": ":not(TSTypeAliasDeclaration:has(> Identifier[name=Undefinable])):has(> TSUnionType:has( > TSUndefinedKeyword):not(:has(> TSNullKeyword)))",
        "message": "Use `Undefinable<T>` utility type instead of `| undefined`."
      },
      {
        "selector": "TSUnionType:has(> TSNullKeyword):has(> TSUndefinedKeyword)",
        "message": "Use `Nilable<T>` utility type instead of `| null | undefined`."
      }
    ]
  }
}

tsconfig.json:

{
    "include": ["src"]
}

test.ts:

type Nullable<T> = T | null;
type Undefinable<T> = T | undefined;
type Nilable<T> = Nullable<Undefinable<T>>;

type x1 = number | null;
type x2 = number | undefined;
type x3 = number | null | undefined;

type x4 = null | number;
type x5 = undefined | number;
type x6 = null | number | undefined;

Моя цель — установить строгие правила использования:

  • Nullable вместо | null
  • Undefinable вместо | undefined
  • Nilable вместо | null | undefined

Я могу достичь этого на playground, но не в своем проекте


Ответы (0 шт):