From cfef56855a9f3b3d7ab5b5954c48f9e3d488263b Mon Sep 17 00:00:00 2001 From: Dhilip H <55967879+hdhilip98@users.noreply.github.com> Date: Thu, 16 Jun 2022 23:24:55 +0530 Subject: [PATCH] Add overloads to onDidChange method to support dot-notation access --- source/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/index.ts b/source/index.ts index d50646d..ddaae1d 100644 --- a/source/index.ts +++ b/source/index.ts @@ -293,14 +293,14 @@ class Conf = Record> implements I /** Watches the given `key`, calling `callback` on any changes. - @param key - The key wo watch. + @param key - The key to watch. @param callback - A callback function that is called on any changes. When a `key` is first set `oldValue` will be `undefined`, and when a key is deleted `newValue` will be `undefined`. @returns A function, that when called, will unsubscribe. */ - onDidChange( - key: Key, - callback: OnDidChangeCallback - ): Unsubscribe { + onDidChange(key: Key, callback: OnDidChangeCallback): Unsubscribe; + // These overloads are used for dot-notation access. + onDidChange(key: Exclude, callback: OnDidChangeCallback): Unsubscribe; + onDidChange(key: string, callback: OnDidChangeCallback): unknown { if (typeof key !== 'string') { throw new TypeError(`Expected \`key\` to be of type \`string\`, got ${typeof key}`); }