Skip to content

Commit

Permalink
feat: specify findOne types (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed Jul 26, 2019
1 parent a70b6fe commit 63f3515
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export class Model<T> {
static findOne<U = any, P extends QueryPart = any>(
primaryKey: PrimaryKey,
orderBy?: Partial<P>
)
): Promise<U | undefined>
static findOne<U extends QueryPart = any, P extends QueryPart = any>(
conditions: Partial<U>,
orderBy?: Partial<P>
)
): Promise<U | undefined>
static findOne<U extends QueryPart = any, P extends QueryPart = any>(
primaryKeyOrCond: PrimaryKey | Partial<U>,
orderBy?: Partial<P>
): Promise<U> {
): Promise<U | undefined> {
const conditions =
typeof primaryKeyOrCond === 'object'
? primaryKeyOrCond
Expand Down Expand Up @@ -211,7 +211,10 @@ export class Model<T> {
const Constructor = this.getConstructor()
const query = conditions ? conditions : this.getDefaultQuery()

this.attributes = await Constructor.findOne<T>(query)
const attributes = await Constructor.findOne<T>(query)
if (attributes) {
this.attributes = attributes
}

return this.attributes
}
Expand Down

0 comments on commit 63f3515

Please sign in to comment.