Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

prefer-for-of false positive on interface with length/indexer #2021

Closed
nchen63 opened this issue Jan 11, 2017 · 4 comments
Closed

prefer-for-of false positive on interface with length/indexer #2021

nchen63 opened this issue Jan 11, 2017 · 4 comments

Comments

@nchen63
Copy link
Contributor

nchen63 commented Jan 11, 2017

Bug Report

  • TSLint version: 4.3.1
  • TypeScript version: 2.1.4
  • Running TSLint via: (please choose one) vscode

TypeScript code being linted

interface FileList {
    readonly length: number;
    item(index: number): File;
    [index: number]: File;
}

// fileList is an instance of a class that implements FileList
for (let i = 0; i < fileList.length; i++) {
}

with tslint.json configuration:

prefer-for-of: true

Actual behavior

indicates that for loop should be for-of

Expected behavior

fileList is not actually an array and TypeScript errors if you try to make it use for-of

@andy-hanson
Copy link
Contributor

This should wait on microsoft/TypeScript#13502. We would need to check assignability to Iterable.

@ajafff
Copy link
Contributor

ajafff commented Mar 26, 2018

FWIW I have a working implementation of prefer-for-of with type information as part of the core rules of the Wotan linter runtime.

@JoshuaKGoldberg
Copy link
Contributor

💀 It's time! 💀

TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. ☠️
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. ✅

👋 It was a pleasure open sourcing with you!

@JoshuaKGoldberg
Copy link
Contributor

🤖 Beep boop! 👉 TSLint is deprecated 👈 (#4534) and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋

@palantir palantir locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants