Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overloads to onDidChange method to support dot-notation access #166

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,14 @@ class Conf<T extends Record<string, any> = Record<string, unknown>> 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 extends keyof T>(
key: Key,
callback: OnDidChangeCallback<T[Key]>
): Unsubscribe {
onDidChange<Key extends keyof T>(key: Key, callback: OnDidChangeCallback<T[Key]>): Unsubscribe;
// These overloads are used for dot-notation access.
onDidChange<Key extends string, Value = unknown>(key: Exclude<Key, keyof T>, callback: OnDidChangeCallback<Value>): Unsubscribe;
onDidChange(key: string, callback: OnDidChangeCallback<unknown>): unknown {
if (typeof key !== 'string') {
throw new TypeError(`Expected \`key\` to be of type \`string\`, got ${typeof key}`);
}
Expand Down