hexojs / warehouse

JSON database

Home Page:https://hexojs.github.io/warehouse/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better typescript types

D-Sketon opened this issue · comments

Check List

  • I have already read README.
  • I have already searched existing issues.
  • I have already searched existing pull requrests.

Feature Request

There are still some problems with the current type labeling for warehouses. For example:

get(fn: (this: T) => any): SchemaTypeVirtual<T> {

Actually, it should be:

get(fn: (this: Document<T>) => any): SchemaTypeVirtual<T> {}

However, it is difficult to refactor the type due to the following implementations:

constructor(data?: T) {
if (data) {
Object.assign(this, data);
}
}

Additional context

No response

One possible solution is to redefine a new type, e.g:

type DocumentType<T> = Document<T> & T

Then replace Document<T> with DocumentType<T> wherever it needs to be used.
But this could be a big change.