-
Notifications
You must be signed in to change notification settings - Fork 27
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
LDContext type is incorrect and errors when accessing kind
property
#94
Comments
kind
property
Hello @johnnywang, thank you for reporting the issue. We will look into this and follow up once we investigated this. Filed internally as 210517. |
Hi @johnnywang, LDContext is a new concept in LaunchDarkly which is an evolution of the legacy LDUser type. An LDContext can be a single-kind, a multi-kind or a legacy LDUser. For backward compatibility for now, we allow using LDUser anywhere we accept a LDContext. The absence of kind is used to know that it is an LDUser. If you are only using LDSingleKindContexts or LDMultiKindContexts, then please use those types instead. We are planning to deprecate and remove LDUser in the future. |
Hey @yusinto! Did you try the repro example above? This TS error happens because there's the |
Hi @johnnywang currently, the In the meantime, to check for context kind, you can do the following: function App() {
const ldClient = useLDClient();
const context = ldClient?.getContext();
// detecting context kind
if (context && 'kind' in context) {
if (context.kind === 'multi') {
console.log(`=== multi context`);
} else {
console.log(`=== single context: ${context.kind}`);
}
} else {
console.log('=== Legacy LDUser');
} |
Describe the bug
If you have a variable of type
LDContext
and try to check/access thekind
property, TS will error out at you saying thatProperty 'kind' does not exist on type 'LDUser'.
To reproduce
Trivial, but something like this should trigger the TS error:
Expected behavior
Accessing
kind
should not throw a TS errorSDK version
"launchdarkly-react-native-client-sdk": "^7.1.5"
Language version, developer tools
React Native
OS/platform
MacOS
Additional context
LDUser should probably extend LDSingleKindContext
The text was updated successfully, but these errors were encountered: