You can create discriminated unions by sharing a single field (e.g. kind) in your type definitions and using a union type in connection with a switch-case statement that helps the TypeScript compiler to distinguish the different types:
TS2339: Property ‘pop‘ does not exist on type ‘readonly [1, 2, 3]‘.
Broken Code ❌
const array = [1, 2, 3] asconst; array.pop();
When using a const assertion on an array, then your array becomes readonly (immutable), so you cannot modify its elements using in-place operations such as pop. You will have to make your array mutable: