Skip to content

Commit

Permalink
fix: improve DX upon wrong useAsync() usage
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Oct 6, 2022
1 parent 334943f commit 0afba57
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/shared/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { stringifyKey }
export { assertKey }

import { stringify } from '@brillout/json-serializer/stringify'
import { isCallable } from '../utils/isCallable'
import { assertUsage } from './utils'

function stringifyKey(key: unknown): string {
Expand All @@ -12,6 +13,10 @@ function stringifyKey(key: unknown): string {
function assertKey(keyValue: unknown) {
assertUsage(
keyValue,
`[useAsync(key, asyncFc)] You provided a \`key\` with the value \`${keyValue}\` which is forbidden.`
`[useAsync(key, asyncFn)] You provided a \`key\` with the value \`${keyValue}\` which is forbidden.`
)
assertUsage(
!isCallable(keyValue),
`[useAsync(key, asyncFn)] You provided a \`key\` that is a function which is forbidden.`
)
}

0 comments on commit 0afba57

Please sign in to comment.