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] Readonly<[A, B]> should be allowed same as readonly [A, B] by allowTupleTypes #3181

Closed
3 tasks done
JounQin opened this issue Mar 13, 2021 · 9 comments
Closed
3 tasks done
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@JounQin
Copy link
Contributor

JounQin commented Mar 13, 2021

  • 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": [
      2,
      {
        "allowAliases": "in-unions-and-intersections",
        "allowCallbacks": "always",
        "allowConditionalTypes": "always",
        "allowConstructors": "always",
        "allowLiterals": "in-unions-and-intersections",
        "allowMappedTypes": "always",
        "allowTupleTypes": "always"
      }
    ]
  }
}
import type { JSXElement, JSXFragment } from '@babel/types'

// if tuple types are used as generic, it should be allowed
export type JsxTypes = Readonly<[JSXElement['type'], JSXFragment['type']]>

export type JsxType = JsxTypes[number] // any option to allow this?

Expected Result

No error

Actual Result

not allowed

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.17.0
@typescript-eslint/parser 4.17.0
TypeScript 4.2.3
ESLint 7.21.0
node 14.16.0
@JounQin JounQin added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Mar 13, 2021
@JounQin
Copy link
Contributor Author

JounQin commented Mar 13, 2021

I think we can add a new option allowGeneric for the first case?

@JounQin
Copy link
Contributor Author

JounQin commented Mar 15, 2021

Actually I just want to disable codes like type A = B, but it's not easy to set for now.

@bradzacher bradzacher added enhancement: plugin rule option New rule option for an existing eslint-plugin rule and removed triage Waiting for maintainers to take a look labels Mar 18, 2021
@JounQin
Copy link
Contributor Author

JounQin commented May 25, 2021

@bradzacher Hi, do you have any idea to help? I'd like to work on it if there is a good option/way to handle type A = B only.

@bradzacher
Copy link
Member

in type A = B, B is a TSTypeReference which falls under allowAliases.

@JounQin
Copy link
Contributor Author

JounQin commented May 25, 2021

@bradzacher I mean disallow type A = B only but allow any other usages.

@bradzacher
Copy link
Member

bradzacher commented May 25, 2021

there is no mechanism to disable just type reference aliases.

All of the options and what they apply to are listed in the docs

You could likely build a selector to match this and block it via no-restricted-syntax - https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#how-can-i-ban-specific-language-feature

@JounQin
Copy link
Contributor Author

JounQin commented May 25, 2021

Thanks, I'll give that a try.

@JounQin
Copy link
Contributor Author

JounQin commented May 26, 2021

@bradzacher Thanks a lot, I finished up by:

{
  'no-restricted-syntax': [
    2,
    {
      selector:
        'TSTypeAliasDeclaration > .typeAnnotation[type=/^(TS.*Keyword|TSTypeReference)$/]:not(:has(TSTypeParameterInstantiation)):not(:has(TSQualifiedName))',
      message:
        'Type alias references simple `Ts*Keyword`s or `TSTypeReference` only is not allowed',
    },
  ],
}

Is it worth to add into no-type-alias's documentation?

@bradzacher
Copy link
Member

bradzacher commented Sep 21, 2021

This can now be allowed broadly via the option added in #3865

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants