Open KODerFunk opened 1 year ago
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?
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
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?
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.
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)
正确的!所以我_认为_ESLint 没有使用默认解析器的变量的类型信息(使用 TypeScript 解析器我们也许能够做到这一点),所以现在我们无法知道标识符
thing
实际上是一个Array
.我说得对吗@amilajack?
Do you have any suggestions to make it work when I use js?
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?
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
@koddsson will this be ported to this repository, or is it a standalone alternative solution?
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
withnot safari < 12
:Project fixed when i add
import 'core-js/features/array/at'
inpages/_app.tsx
.Plugin added correctly, and have setting in
.eslintrc.json
:Added because Next add some (3) polyfills underhood.