It is up to you. Both of these are valid and idiomatic TypeScript:
export class Greeter {
name: '';
sayHello() {
console.log('hello');
}
}
and
export const greeter = {
name : '',
sayHello: () => {
console.log('hello');
}
}
// if you need just the type of greeter for some reason
export type Greeter = typof greeter;
If you don't have a need for the class, don't use them.
But you may find benefits of classes if you want to:
- manage your dependencies with Dependency Injection
- use multiple instances
- use polymorphism
If you have multiple instances, using classes or prototype constructor functions, allow you to share method implementations across all instances.
Even if you are in a purely functional paradigm, using prototype constructor functions or classes can be useful for creating monads.
If you only have one instance, and do not need for a constructor, an object is is probably fine.
(new greeter).Nameis a stringgreeter.Nameis a string