Skip to content

fourslash's verifyRangesAreRenamedLocations has nonsensical code #21283

@sandersn

Description

@sandersn
        public verifyRangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] }) {
            const ranges = ts.isArray(options) ? options : options && options.ranges || this.getRanges();
            this.verifyRenameLocations(ranges, { ranges, ...options });
        }

When options is a Range[], the object spread creates an object that is like an array, except without its methods, and with a property named ranges that is the array itself. This works fine because of the way that verifyRenameLocations uses ts.isArray (the spread object never is), but should probably be something more like:

  const ranges = ts.isArray(options) ? options : options.ranges || this.getRanges();
  this.verifyRenameLocations(ranges, ts.isArray(options) ? options : { ranges, ...options });

Found while working on excess property checks, although this usage is not actually an error in the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    InfrastructureIssue relates to TypeScript team infrastructure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions