I'm attempting to convert a const object into a class in order to create readonly properties. The goal is to ensure that the values in these properties never change.
Specifically, I'm trying to create a module property in my class that is defined but always empty.
I've experimented with a few different approaches:
public modules: Readonly<[]> = []; // Causes an error: A tuple type element list cannot be empty.
public readonly modules: IModule[] = []; // Prevents re-assignment but still allows modification with methods like push and pop.
interface EmptyTuple {
length: 0;
}
// Encounter an error stating types of property 'length' are incompatible, where 'number' is not assignable to '0'.
public modules: Readonly<EmptyTuple> = [];
The most recent attempt doesn't seem logical, as 0 is essentially a number. I'm feeling a bit lost here, so any guidance would be greatly appreciated.
I searched through https://github.com/Microsoft/TypeScript/issues/13126 in hopes of finding a solution, but unfortunately came up empty-handed.
Is there anyone who knows how to create an unmodifiable empty array?