Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[no-type-alias] Unhandled in union types are not allowed for keyof or typeof #3202

Closed
3 tasks done
mscharley opened this issue Mar 19, 2021 · 0 comments · Fixed by #3242
Closed
3 tasks done

[no-type-alias] Unhandled in union types are not allowed for keyof or typeof #3202

mscharley opened this issue Mar 19, 2021 · 0 comments · Fixed by #3242
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@mscharley
Copy link

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
        "@typescript-eslint/no-type-alias": [
          "error",
          {
            "allowAliases": "in-unions-and-intersections",
            "allowLiterals": "in-unions-and-intersections",
            "allowCallbacks": "always",
            "allowConditionalTypes": "always",
            "allowConstructors": "always",
            "allowMappedTypes": "always",
            "allowTupleTypes": "always"
          }
        ],
  }
}
// your repro code case
const SCALARS = {
  Jwt: {}, // Some value here, I don't think it matters for the below code.
} as const;
const FixedNames = {
  Jwt: 'JWT',
} as const;
type FixedNames = typeof FixedNames extends Record<string, infer U> ? U : never;
type ScalarGenerator = (container: interfaces.Container) => GraphQLScalarType;
// Error is triggered on this line.
type ScalarNames = FixedNames | keyof typeof SCALARS;
// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2017",
    "lib": [
      "es5",
      "es2015",
      "es2016",
      "es2017",
      "dom",
      "esnext.asynciterable"
    ],
    "module": "commonjs",
    "moduleResolution": "Node",
    "typeRoots": ["./types", "./node_modules/@types"],
    "strict": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "rootDir": "./src",
    "outDir": "./dist"
  },
  "include": [
    "./src/**/*",
    "./types/**/*.d.ts"
  ]
}

Expected Result

I would expect this type of construct to either be allowed or be configurable.

Actual Result

"Unhandled in union types are not allowed"

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.18.0
@typescript-eslint/parser 4.18.0
TypeScript 4.2.3
ESLint 7.22.0
node 12.13.1
@mscharley mscharley added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 19, 2021
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Mar 19, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants