chore: mesurer la forme du tableau au lieu de la supposer, et retirer les any

La branche tableau se decide sur `typeof cible.length === "number"`, ce qui est
une question posee a un proxy : mesure contre le vrai
`@ng-org/alien-deepsignals`, `deepSignal(new Set(...)).length` vaut `undefined`
et ses `Object.keys` sont vides, tandis que `deepSignal([...]).length` est un
nombre. La forme ensemble n-entre donc jamais dans cette branche, et c-est aussi
celle qui ne porte aucune cle nommant un objet.

Les trois `as any` des tests ajoutes et le `Iterable<any>` du harness sont
types.
This commit is contained in:
Sylvain Duchesne
2026-09-24 18:39:33 +02:00
parent e86e249a5a
commit b1b099b6c7
3 changed files with 18 additions and 10 deletions
+7 -7
View File
@@ -149,10 +149,10 @@ test("forEach is filtered too", () => {
// hatch included, which `get` refuses by name. Everything built on that call goes the same
// way: `Object.keys`, `Object.entries`, a spread, `JSON.stringify`, a console inspection.
test("a descriptor cannot answer what reading the member refuses", () => {
const set = new Set<Item>([MINE]) as any;
const set: Set<Item> & { __raw__?: unknown } = new Set<Item>([MINE]);
set.__raw__ = set;
const { caps, become } = setup("alice");
const view = makeReadFilteredView(set, caps) as any;
const view = makeReadFilteredView(set, caps);
become("bob");
expect(() => Object.getOwnPropertyDescriptor(view, "__raw__")).toThrow(/raw collection/i);
});
@@ -163,9 +163,9 @@ test("a descriptor cannot answer what reading the member refuses", () => {
// count of what a holder may NOT read came back out through the other three, and the
// descriptor handed back the items themselves.
test("the array form counts and addresses the readable items, by every route", () => {
const items = [MINE, FOREIGN, LINKED];
const items: Item[] = [MINE, FOREIGN, LINKED];
const { caps, become } = setup("alice");
const view = makeReadFilteredView(items, caps) as any;
const view = makeReadFilteredView(items, caps);
become("bob"); // holds nothing of the three documents
expect(view.length).toBe(0);
@@ -178,9 +178,9 @@ test("the array form counts and addresses the readable items, by every route", (
become("alice"); // holds her own document and the one she published
expect(view.length).toBe(2);
expect(Object.keys(view)).toEqual(["0", "1"]);
expect(view[0].id).toBe("a");
expect(view[1].id).toBe("p");
expect(Object.getOwnPropertyDescriptor(view, "1")?.value.id).toBe("p");
expect(view[0]).toBe(MINE);
expect(view[1]).toBe(LINKED);
expect(Object.getOwnPropertyDescriptor(view, "1")?.value).toBe(LINKED);
expect(2 in view).toBe(false);
// `length` is the array's own key and is never hidden - a proxy may not drop a key the
// target cannot configure away - but it is not a position and does not enumerate.