You should consider whether such a huge object makes sense. Classes that do everything are generally a bad idea, you should split them up in several classes that each deals with a specific object type (ie one class for Balls, one for Candies etc.) and use those classes. If you want to share code you can put it in a base class (preferably an abstract base class if it has no concrete functionality). A solution might look like this:
export abstract class MyStorage implements Storage {
}
export class CandiesStorage extends MyStorage {
getCandies() {}
}
export class BallsStorage extends MyStorage {
}
That being said, if for your own reasons this is not feasible, you can split up the functions like this, you just have the operator wrong, you need to initialize the Candies field with = not with : (: is a type annotation not field initialization inside a class). One problem with this approach is that inside the object literal functions (for example getCandies), this will refer to the object literal if you use regular functions. The simplest solution would be to use an arrow function or to add an extra owner field to allow access to the containing class instance. Here is a solution that exemplifies both options:
export class MyStorage implements Storage {
public constructor (){ }
Candies = {
getCandies: () => {
this.Balls // this refers to MyStorage
}
}
Balls = {
owner: this, // capture the owner object in a field
getBalls() {
this.owner.Candies // this refers to the Balls objects, but we can use owner to access the container
}
}
}
MyStoragean abstract class. Then create subclasses extendingMyStorage.export class CandiesStorage extends MyStoragecandyStorage,ballStorage,flowersStorageetc.