Skip to content

Commit

Permalink
refactor: add a type check on AbortSignal
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Oct 20, 2022
1 parent a411dcc commit b013fef
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,15 @@ function prepareHeaders(input: unknown): Headers {
}

function signal(value: Exclude<HttpRequestOptions['signal'], undefined>): AbortSignal {
return value instanceof AbortSignal ? value : value()
if (typeof value === 'function') {
value = value()
}

if (!(value instanceof AbortSignal)) {
throw new TypeError('"options.signal" must return or be an instance of AbortSignal')
}

return value
}

/**
Expand Down

0 comments on commit b013fef

Please sign in to comment.