Files
scriptc/tests/corpus/2796-array-sparse-class-value-instanceof.ts
Chris Tate 94fd361b54 Implement sparse native arrays and missing-value parity (#297)
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
2026-09-12 22:39:07 -05:00

22 lines
642 B
TypeScript

// Both operands of instanceof evaluate before its result is chosen. A hole
// on the left behaves as undefined and returns false with a present class;
// a hole on the right still throws even when the left is missing.
class Item {}
class Child extends Item {}
const values: Item[] = [];
values[1] = new Item();
const classes: (typeof Item)[] = [];
classes[1] = Item;
const missingValue = values[0];
const presentClass = classes[1];
console.log(missingValue instanceof presentClass);
const missingClass = classes[0];
try {
console.log(missingValue instanceof missingClass);
} catch (error) {
console.log(error instanceof TypeError);
}