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 ts errors when remix-sdk client is imported #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { LDClient, LDFlagSet, LDUser } from 'launchdarkly-js-client-sdk';

import useFlags from '../shared/useFlags';
import useLDUser from '../shared/useLDUser';

import LDBrowser from './ldBrowser';

declare global {
interface Window {
ldClientBrowser: LDClient;
ssrFlags: LDFlagSet;
ldUser: LDUser;
clientSideID: string;
}
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for issues 2, 3, and 4. For some reason, tsc isn't able to access the globals.d.ts file in this project when client is pulled in.

export { LDBrowser, useFlags, useLDUser };
4 changes: 2 additions & 2 deletions src/client/ldBrowser.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { Component, ReactNode } from 'react';
import { Component, ReactNode } from 'react';
import { initialize, LDFlagChangeset, LDFlagSet } from 'launchdarkly-js-client-sdk';

import { LDContext as HocState, Provider } from '../shared/context';
import { getFlattenedFlagsFromChangeset } from '../shared/utils';

type LDBrowserProps = { children: ReactNode };

class LDBrowser extends Component<LDBrowserProps, HocState> {
readonly state: Readonly<HocState>;

Expand All @@ -31,6 +30,7 @@ class LDBrowser extends Component<LDBrowserProps, HocState> {
}

render() {
// eslint-disable-next-line react/react-in-jsx-scope
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for issue 1 - removing React on line 1 above fixes the issue, but eslint will flag the line below.

return <Provider value={this.state}>{this.props.children}</Provider>;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/shared/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createContext } from 'react';
import type { LDClient as LDJSClient, LDUser, LDFlagSet } from 'launchdarkly-js-client-sdk';
import type { LDClient as LDJSClient, LDFlagSet, LDUser } from 'launchdarkly-js-client-sdk';

interface LDContext {
flags: LDFlagSet;
Expand All @@ -10,5 +10,6 @@ interface LDContext {
const context = createContext<LDContext>({ flags: {}, ldClient: undefined, user: undefined });
const { Provider, Consumer } = context;

export { Provider, Consumer, LDContext };
export { Provider, Consumer };
export type { LDContext };
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix for issue 5.

export default context;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"jsx": "react",
"jsx": "react-jsx",
"esModuleInterop": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true
Expand Down