Skip to content

Commit

Permalink
Add missing clear method to Cache type definition
Browse files Browse the repository at this point in the history
The Cache has been exposed since [1], which supposedly includes a
.clear() method [2], which in turn is not actually present in the
type definition [3]. This adds it to the type definition to align
with the implementation.

Since Map also contains a .clear() method [4], this shouldn't break
the ability to pass that in as a map.

[1] #231
[2] #161 (comment)
[3] #161 (comment)
[4] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/clear
  • Loading branch information
Vinnl committed Apr 20, 2022
1 parent dc78549 commit 763c473
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,5 @@ export interface Cache<Data = any> {
get(key: Key): Data | null | undefined
set(key: Key, value: Data): void
delete(key: Key): void
clear(): void
}
3 changes: 2 additions & 1 deletion test/use-swr-cache.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ describe('useSWR - cache provider', () => {
}
return v
},
delete: k => parentCache_.delete(k)
delete: k => parentCache_.delete(k),
clear: () => parentCache_.clear()
}
}
})
Expand Down

0 comments on commit 763c473

Please sign in to comment.