Skip to content

Bug: Visitor keys for 5 types are not in source order #11276

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

Closed
4 tasks done
overlookmotel opened this issue Jun 5, 2025 · 1 comment · Fixed by #11279
Closed
4 tasks done

Bug: Visitor keys for 5 types are not in source order #11276

overlookmotel opened this issue Jun 5, 2025 · 1 comment · Fixed by #11279
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: visitor-keys Issues related to @typescript-eslint/visitor-keys

Comments

@overlookmotel
Copy link
Contributor

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Relevant Package

visitor-keys

Playground Link

https://typescript-eslint.io/play/#ts=5.8.2&showAST=es&fileType=.tsx&code=PQKgUABCECoMoEkC2AHA9gJwC4wJ4oFNJoBpA3AZwC4Ja6BtAcgEMMBzAVyQIDstGANBEYBHDswA2ASwBmUghkHCs%2BAgEF2XXlgpLGaFFiloeugLrEIcABZoOEgCYQARgRpNWnbnz0GjJ3SFRcWk5BT0VQg0vbXNiYDBIggg1CABeCClUTCwACkYZNDQlAG8IZgoKBSwaMsYMAgo0CQ5-HgBaJDQHAkYaRiz0bEYIAF8xgEoAOjFJWXkMAB4YAD4AbjBgYDpaTy0%2BCAA9Y%2BPN7Z2Luj9jUyOT%2B4fHp%2BeXs8v3j8%2Bv74vZ0IW7k83j8QaCwZcktF9jpAWBNuAoLBEDwegAPAgONQAYyxjQoeEIljIlBoFyYUhRBFRBN6QTQzgAVgQsThVIwLIibHZHC43BAmPSmSyaXoKWiRRyQAkkhAAELpCAABQUTR49AARMw2AR1RAAD4QdU8ZjcdVmDZbd6PCCC5mswmWn4vJ6ZSnU1Rw0CWeAAWQIWFsDjgUjYxqwHAaRPI1EuTCSitYJv9Kr0AGtyHoUImkIFhA1wxgeBLLFz7E5XO5GOncBFVAmMEmsCmglmGzm9PmI0W2ZKEhSmxgZMxcRAAGJFCBlZysZYrXLMGg8LiuDATGgULAYClsNZjYEfauwx3x7PJjAUI-nH6tk0X16O8E7TuFmmAk6ehHQeCKjAGaq4YNQ2YAsiERYkYzJRhIR4Hg0CwYCbjTDNJSsWwy15Stq1rKIYLghCTHZeIwH7BQhxHWVWEnCAxFRRdlwUPcH3eQ93yY6DYPgto31OeFvTgGkfwxKQsWA0DSGjUkdjjVQ1FwzjEJbU8BwAOSTQjOTQnkK35Rgb24FS1KCdi8LadSpTAGQOB4FkbkyCg4E3bdciQZhcG0qzU1ggB3Hg1wgFy3OSKQLw3LceDYKjnx4CAkjQGR-Nc1x0jSDJGFC7dGF3UZ93BPSz1U7huJyx8IRkuT8Oix4wCAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

/*
 * TSImportType
 * Keys:      ['argument', 'qualifier', 'typeArguments', 'options']
 * Should be: ['argument', 'options', 'qualifier', 'typeArguments']
 */
type A = import('foo', { assert: { 'resolution-mode': 'import' } }).qualifier<T>;
//     argument ^^^^^
//             options ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                                                        qualifier ^^^^^^^^^
//                                                             typeArguments ^^^

/*
 * TSIndexedAccessType
 * Keys:      ['indexType', 'objectType']
 * Should be: ['objectType', 'indexType']
 */
type B = Person["age" | "name"];
//       ^^^^^^ objectType
//             ^^^^^^^^^^^^^^^^ indexType

/*
 * TSMethodSignature
 * Keys:      ['typeParameters', 'key', 'params', 'returnType']
 * Should be: ['key', 'typeParameters', 'params', 'returnType']
 */
interface Foo { bar<T>(a: number): string; }
//          key ^^^
//  typeParameters ^^^
//              params ^^^^^^^^^
//                      returnType ^^^^^^

/*
 * TSPropertySignature
 * Keys:      ['typeAnnotation', 'key']
 * Should be: ['key', 'typeAnnotation']
 */
interface Bar { qux: number }
//          key ^^^
//    typeAnnotation ^^^^^^

/*
 * TSTypePredicate
 * Keys:      ['typeAnnotation', 'parameterName']
 * Should be: ['parameterName', 'typeAnnotation']
 */
function isString(maybe: unknown): maybe is string { return typeof maybe === 'string'; }
//                   parameterName ^^^^^
//                           typeAnnotation ^^^^^^

ESLint Config

tsconfig

Expected Result

A comment in visitor-keys package states that keys "should be sorted in the order that they appear in the source code".

/*
********************************** IMPORTANT NOTE ********************************
* *
* The key arrays should be sorted in the order in which you would want to visit *
* the child keys. *
* *
* DO NOT SORT THEM ALPHABETICALLY! *
* *
* They should be sorted in the order that they appear in the source code. *
* For example: *
* *
* class Foo extends Bar { prop: 1 } *
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ClassDeclaration *
* ^^^ id ^^^ superClass *
* ^^^^^^^^^^^ body *
* *
* It would be incorrect to provide the visitor keys ['body', 'id', 'superClass'] *
* because the body comes AFTER everything else in the source code. *
* Instead the correct ordering would be ['id', 'superClass', 'body']. *
* *
**********************************************************************************
*/

This is not the case for 5 types:

  • TSImportType
  • TSIndexedAccessType
  • TSMethodSignature
  • TSPropertySignature
  • TSTypePredicate

Please see above for examples.

Actual Result

Properties are visited not in source code order.

Additional Info

No response

Versions

package version
@typescript-eslint/visitor-keys 8.33.1
@overlookmotel overlookmotel added bug Something isn't working triage Waiting for team members to take a look labels Jun 5, 2025
@kirkwaiblinger
Copy link
Member

Hi @overlookmotel!

Makes sense, opening for PRs. Thanks!

@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Jun 5, 2025
@bradzacher bradzacher added the package: visitor-keys Issues related to @typescript-eslint/visitor-keys label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: visitor-keys Issues related to @typescript-eslint/visitor-keys
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants