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

Dont work with Array.prototype.at #539

Open
KODerFunk opened this issue Feb 10, 2023 · 9 comments
Open

Dont work with Array.prototype.at #539

KODerFunk opened this issue Feb 10, 2023 · 9 comments

Comments

@KODerFunk
Copy link

KODerFunk commented Feb 10, 2023

I have Next.js (13) project, in code i use ['some', 'arrays'].at(-1) and dont has error from this plugin.

Array.prototype.at supports in Safari 15.4: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
but i have correct .browserlistrc with not safari < 12:

last 2 versions
since 2018
node 17

not dead
not android < 5
not op_mini all
not opera < 64
not ios_saf < 12.2
not safari < 12
not edge < 100
not firefox < 100
not chrome < 80

Project fixed when i add import 'core-js/features/array/at' in pages/_app.tsx.

Plugin added correctly, and have setting in .eslintrc.json:

      "settings": {
        "polyfills": [
          "URL.createObjectURL",
          "URL.revokeObjectURL"
        ]
      },

Added because Next add some (3) polyfills underhood.

@koddsson
Copy link
Contributor

Is this still not working in the latest version (4.1.4)? I think I've fixed it there. If not still working, can you provide a small reproduction case that we can take a look at?

@MetRonnie
Copy link

Hmm, I guess this is a little tricky because I guess ESLint doesn't know the types of variables?

const thing = [4, 5, 6]

const a = thing.at(2) // no error
const b = [4, 5, 6].at(2) // correct error

https://github.com/MetRonnie/eslint-plugin-compat-demo/tree/issue-539

@koddsson
Copy link
Contributor

koddsson commented May 3, 2023

Right! So I think that ESLint doesn't have the type information of the variable using the default parser (using the TypeScript parser we might be able to do that) so as it stands now we can't know that the thing identifier is in fact an Array.

Am I getting that right @amilajack?

@antoniosteiger
Copy link

antoniosteiger commented Jan 30, 2024

FYI, This is still not working, just tested it with the following code:

let c = [4, 5, 6]; let b = c.findLastIndex();

findLastIndex() is only supported in Chrome 97+, but in my browserlist I have chrome >= 80. Compat doesn't flag this.
I am using ESLint's default parser with sourceType module.

@mintplo
Copy link

mintplo commented Mar 3, 2024

FYI, This is still not working too.

.browserslistrc

Chrome >= 92
Safari >= 15.4
Firefox >= 90
Edge >= 92
[].findLast() ✅ (eslint checked)
people.list.findLast ❌ (eslint no-checked)

CleanShot 2024-03-03 at 11 15 10@2x

@tantian1498
Copy link

正确的!所以我_认为_ESLint 没有使用默认解析器的变量的类型信息(使用 TypeScript 解析器我们也许能够做到这一点),所以现在我们无法知道标识符thing实际上是一个Array.

我说得对吗@amilajack

Do you have any suggestions to make it work when I use js?

@tantian1498
Copy link

Hmm, I guess this is a little tricky because I guess ESLint doesn't know the types of variables?

const thing = [4, 5, 6]

const a = thing.at(2) // no error
const b = [4, 5, 6].at(2) // correct error

https://github.com/MetRonnie/eslint-plugin-compat-demo/tree/issue-539

i have the same problem, do you solve it now?

@koddsson
Copy link
Contributor

I took a stab at implementing eslint-plugin-compat using the TypeScript parser so that the rule has type information and linting code like has been referenced in this issue should be possible (check out the unit tests).

I would appreciate if people in this thread would give it a go and file issues if there's something wrong with it.

Check out the repo: https://github.com/koddsson/eslint-plugin-tscompat

@dartess
Copy link
Contributor

dartess commented Jul 31, 2024

@koddsson will this be ported to this repository, or is it a standalone alternative solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants