diff --git a/.changeset/cool-schools-search.md b/.changeset/cool-schools-search.md new file mode 100644 index 00000000..b7bd8518 --- /dev/null +++ b/.changeset/cool-schools-search.md @@ -0,0 +1,6 @@ +--- +'@featureboard/node-sdk': minor +'@featureboard/js-sdk': minor +--- + +[TypeScript] Annotated SDK functions with 'this: void' to indicate the methods can be destructured without needing to be bound diff --git a/libs/js-sdk/src/client-connection.ts b/libs/js-sdk/src/client-connection.ts index bbafb1c0..11843b0f 100644 --- a/libs/js-sdk/src/client-connection.ts +++ b/libs/js-sdk/src/client-connection.ts @@ -11,7 +11,7 @@ export interface BrowserClient { * * @throws {Error} If the initialisation process fails an error is thrown */ - waitForInitialised(): Promise + waitForInitialised(this: void): Promise /** Subscribe to initialised changes, will call back with initialised boolean value * Recommended to be used in conjunction with updateAudiences() @@ -19,15 +19,16 @@ export interface BrowserClient { * @returns unsubscribe function */ subscribeToInitialisedChanged( + this: void, callback: (initialised: boolean) => void, ): () => void /** Will set initialised to false until the new audiences are loaded */ - updateAudiences(audiences: string[]): PromiseLike + updateAudiences(this: void, audiences: string[]): PromiseLike /** Manually triggers an update to the feature state */ - updateFeatures(): PromiseLike + updateFeatures(this: void): PromiseLike /** Closes subscription to the FeatureBoard service */ - close: () => void + close: (this: void) => void } diff --git a/libs/js-sdk/src/features-client.ts b/libs/js-sdk/src/features-client.ts index c26337e4..721f6452 100644 --- a/libs/js-sdk/src/features-client.ts +++ b/libs/js-sdk/src/features-client.ts @@ -3,6 +3,7 @@ import type { FeatureBoardEffectiveStateJS } from './js-state' export interface FeatureBoardClient { getFeatureValue( + this: void, featureKey: T, defaultValue: Features[T], ): Features[T] @@ -13,10 +14,11 @@ export interface FeatureBoardClient { * @returns unsubscribe function */ subscribeToFeatureValue( + this: void, featureKey: keyof Features, defaultValue: Features[T], onValue: (value: Features[T]) => void, ): () => void - getEffectiveValues(): FeatureBoardEffectiveStateJS + getEffectiveValues(this: void): FeatureBoardEffectiveStateJS } diff --git a/libs/node-sdk/src/server-connection.ts b/libs/node-sdk/src/server-connection.ts index b9e02516..bf146442 100644 --- a/libs/node-sdk/src/server-connection.ts +++ b/libs/node-sdk/src/server-connection.ts @@ -11,6 +11,7 @@ export interface ServerClient { * immediately call back with the current value and will not subscribe to the feature in the state store. **/ request( + this: void, audiences: string[], ): FeatureBoardClient & PromiseLike @@ -22,10 +23,10 @@ export interface ServerClient { * * @throws {Error} If the initialisation process fails an error is thrown */ - waitForInitialised(): Promise + waitForInitialised(this: void): Promise /** Manually triggers an update to the feature state */ - updateFeatures(): PromiseLike + updateFeatures(this: void): PromiseLike - close(): void + close(this: void): void }