Skip to content

Commit

Permalink
Fix typings for promises
Browse files Browse the repository at this point in the history
  • Loading branch information
mupperton committed Oct 11, 2022
1 parent be8af9b commit 425e3ed
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/phunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Config {
const noop = () => {}

class Phunk<T> {
#fn: () => T
#fn: () => T | Promise<T>

#promise: Promise<T> | null = null

Expand All @@ -20,7 +20,7 @@ class Phunk<T> {
#ttl
#lastResolve = 0

constructor(fn: () => T, config?: Config) {
constructor(fn: () => T | Promise<T>, config?: Config) {
const options = config ?? {}

if (typeof options.ttl !== 'undefined' && (!Number.isSafeInteger(options.ttl) || options.ttl < 0)) {
Expand Down Expand Up @@ -59,7 +59,7 @@ class Phunk<T> {
if (!this.#isResolving) {
this.#promise = this.#resolve()
}
return this.#promise
return this.#promise as Promise<T>
}

async #resolve() {
Expand Down

0 comments on commit 425e3ed

Please sign in to comment.