Skip to content

Commit

Permalink
Add TypeScript overload for .delete() to fix dot-notation typing (#197
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gching authored Dec 7, 2024
1 parent 05f1b87 commit 8fdcdd7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ export default class Conf<T extends Record<string, any> = Record<string, unknown
@param key - The key of the item to delete.
*/
delete<Key extends keyof T>(key: Key): void;
// This overload is used for dot-notation access.
delete(key: string): void;
delete(key: string): void {
const {store} = this;
if (this.#options.accessPropertiesByDotNotation) {
Expand Down
2 changes: 2 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ expectType<string>(conf.get('foo'));
expectType<string>(conf.get('foo', 'bar'));
conf.delete('foo');
expectType<boolean>(conf.has('foo'));
conf.delete('nested.prop');
expectType<boolean>(conf.has('nested.prop'));
conf.clear();
const off = conf.onDidChange('foo', (oldValue, newValue) => {
expectAssignable<UnicornFoo[keyof UnicornFoo]>(oldValue);
Expand Down

0 comments on commit 8fdcdd7

Please sign in to comment.