How can I declare type of an ES6 module in Typescript?

Viewed 1656

I have a generic interface for a repository like this.

export interface IBaseRepository<T> {
    create(model: T): T;
    edit(model: T): T;
    read(): T
}

I'm trying to implement this repository interface in a functional module like this (since it's basically a stateless singleton).

// user-repository.ts
export function create(model: IUser): IUser { ...code }

export function edit(model: IUser): IUser { ...code }

export function read(): IUser { ...code }

Is there any way to ensure that IBaseRepository is implemented in UserRepository. Or do I have to always implement the repository as a class and export an instantiated singleton?

2 Answers
Related