Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refactor types #261

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ async function exportAsync(database: Database, path: string): Promise<void> {
interface DatabaseOptions {
version: number,
path: string,
onUpgrade: (...args: any[]) => any,
onDowngrade: (...args: any[]) => any
onUpgrade: (oldVersion: number, newVersion: number) => any,
onDowngrade: (oldVersion: number, newVersion: number) => any
}

class Database {
Expand Down
10 changes: 5 additions & 5 deletions src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import rfdc from 'rfdc';
import type Model from './model';
import type Schema from './schema';
import type BluebirdPromise from 'bluebird';
import type { NodeJSLikeCallback } from './types';
import type { NodeJSLikeCallback, Options } from './types';
const cloneDeep = rfdc();

abstract class Document<T> {
abstract _model: Model<T>;
_id!: string | number | undefined;
_id!: string;
abstract _schema: Schema<T>;
[key : string]: any;

Expand Down Expand Up @@ -69,7 +69,7 @@ abstract class Document<T> {
*
* @return {object}
*/
toObject(): T {
toObject(): T extends object ? T : never {
const keys = Object.keys(this);
const obj: Partial<T> = {};

Expand All @@ -80,7 +80,7 @@ abstract class Document<T> {
obj[key] = isGetter(this, key) ? this[key] : cloneDeep(this[key]);
}

return obj as T;
return obj as T extends object ? T : never;
}

/**
Expand All @@ -98,7 +98,7 @@ abstract class Document<T> {
* @param {String|Object} expr
* @return {Document}
*/
populate(expr: string | any[] | { path?: string; model?: any; [key: PropertyKey]: any }): Document<T> {
populate(expr: string | string[] | Partial<Options>[] | Partial<Options>): Document<T> {
const stack = this._schema._parsePopulate(expr);
return this._model._populate(this, stack);
}
Expand Down
Loading
Loading