eslint-plugin-total-functions icon indicating copy to clipboard operation
eslint-plugin-total-functions copied to clipboard

[no-unsafe-readonly-mutable-assignment]: problem with [Symbol.iterator]

Open Perfectoff opened this issue 3 years ago • 1 comments

It seems that this rule does not work correctly with [Symbol.iterator]. I'm trying to cast a readonly array to a readonly Iterable, but I get an error: "Using a readonly type to initialize a mutable type can lead to unexpected mutation in the readonly value."

const arr : readonly number[] = [];

const it1 : Iterable<number> = arr; // error!

const it2 : Readonly<Iterable<number>> = arr; // error!

So what should I do about it?

Perfectoff avatar Apr 14 '22 19:04 Perfectoff

Well, the problem is even worse. We can't even do this:

const arr : readonly number[] = [];
const obj : {} = arr; // error!

Perfectoff avatar Apr 14 '22 20:04 Perfectoff

Fixed in v6.6.1

danielnixon avatar Mar 10 '23 09:03 danielnixon