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

The keys in the options argument to ReferenceTracker should be optional #3526

Closed
3 tasks done
MageJohn opened this issue Jun 14, 2021 · 2 comments · Fixed by #3531
Closed
3 tasks done

The keys in the options argument to ReferenceTracker should be optional #3526

MageJohn opened this issue Jun 14, 2021 · 2 comments · Fixed by #3531
Labels
bug Something isn't working package: utils Issues related to the @typescript-eslint/utils package

Comments

@MageJohn
Copy link
Contributor

MageJohn commented Jun 14, 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

import { ASTUtils } from "@typescript-eslint/experimental-utils";
const { ReferenceTracker } = ASTUtils;

const tracker1 = new ReferenceTracker(context.getScope(), {});
const tracker2 = new ReferenceTracker(context.getScope(), {
  mode: "legacy"
});
const tracker3 = new ReferenceTracker(context.getScope(), {
  globalObjectNames: ["global", "globalThis", "self", "window"]
});

Expected Result

All the ReferenceTracker constructions above are should be valid, with no type errors.

Actual Result

Each of them produces a type error. For example, tracker1 produces this:

Argument of type '{}' is not assignable to parameter of type '{ mode: "strict" | "legacy"; globalObjectNames: readonly string[]; }'.
  Type '{}' is missing the following properties from type '{ mode: "strict" | "legacy"; globalObjectNames: readonly string[]; }': mode, globalObjectNames

Additional Info

The options object for ReferenceTracker should have all it's keys as optional. The implementation from eslint-utils looks like this:

constructor(
    globalScope,
    {
        mode = "strict",
        globalObjectNames = ["global", "globalThis", "self", "window"],
    } = {},
) {
  // ...
}

Versions

package version
@typescript-eslint/experimental-utils 4.26.1
TypeScript 4.3.2
node 12.22.0
@MageJohn MageJohn added package: utils Issues related to the @typescript-eslint/utils package triage Waiting for maintainers to take a look labels Jun 14, 2021
@bradzacher
Copy link
Member

Happy to accept a PR.
With this sort of thing it's usually better and faster to just raise a PR with context in the description rather than raising an issue first.

@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for maintainers to take a look labels Jun 14, 2021
@MageJohn
Copy link
Contributor Author

Cool, on it now!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 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: utils Issues related to the @typescript-eslint/utils package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants