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

fix(types): LDClient.waitForInitialization resolves this #459

Conversation

SevenOutman
Copy link

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

#324

Describe the solution you've provided

Type the return type with this keyword

Describe alternatives you've considered

Additional context

In my use case, the problem was that the return type of waitForInitialization is not compatible with ld.LDClient

import * as ld from '@launchdarkly/node-server-sdk';

export function initLdClient(): Promise<ld.LDClient> {
  return ld.init(process.env.LAUNCH_DARKLY_SDK_KEY as string)
           .waitForInitialization(); // Type error
}

@SevenOutman SevenOutman force-pushed the fix/LDClient-waitForInitialization-resolve-this branch from 68c4f4d to e104e53 Compare May 10, 2024 04:20
@chadxz
Copy link

chadxz commented May 15, 2024

In the docs for the waitForInitialization method, it says:

It is not recommended to use the returned client object. It will be removed in a future version.

FYI.

@kinyoklion
Copy link
Member

kinyoklion commented May 20, 2024

Hello @SevenOutman,

As @chadxz mentioned we have updated the docs to indicate the return value here will be removed in the future.

Some previous discussion: #324

I would recommend something like this instead.

export async function initLdClient(): Promise<ld.LDClient> {
  const client =  ld.init(process.env.LAUNCH_DARKLY_SDK_KEY as string);
  await client.waitForInitialization();
  return client;
}

(The fix is nice though.)

Thank you,
Ryan

@SevenOutman
Copy link
Author

Understood. Thanks both! I'm closing the PR.

@SevenOutman SevenOutman deleted the fix/LDClient-waitForInitialization-resolve-this branch May 21, 2024 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants