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

Conversation

kronkm
Copy link

@kronkm kronkm commented Sep 2, 2022

Fixing type errors that are thrown when the remix-sdk client exports are pulled into a project with stricter tsconfig options and imported via:

import { useFlags } from 'node_modules/remix-sdk/src/client';

My project is using typescript@4.7.4. Right now, projects with stricter TS settings can throw these errors:

1:

node_modules/remix-sdk/src/client/ldBrowser.tsx:1:8 - error TS6133: 'React' is declared but its value
is never read.

1 import React, { Component, ReactNode } from 'react';
         ~~~~~

2, 3, 4:

node_modules/remix-sdk/src/client/ldBrowser.tsx:14:13 - error TS2339: Property 'ssrFlags' does not
exist on type 'Window & typeof globalThis'.

14     const { ssrFlags, clientSideID, ldUser } = window;
               ~~~~~~~~

node_modules/remix-sdk/src/client/ldBrowser.tsx:14:23 - error TS2339: Property 'clientSideID' does not
exist on type 'Window & typeof globalThis'.

14     const { ssrFlags, clientSideID, ldUser } = window;
                         ~~~~~~~~~~~~

node_modules/remix-sdk/src/client/ldBrowser.tsx:14:37 - error TS2339: Property 'ldUser' does not
exist on type 'Window & typeof globalThis'.

14     const { ssrFlags, clientSideID, ldUser } = window;
                                       ~~~~~~

5:

node_modules/remix-sdk/src/shared/context.ts:13:30 - error TS1205: Re-exporting a type
when the '--isolatedModules' flag is provided requires using 'export type'.

13 export { Provider, Consumer, LDContext };

@@ -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.

@@ -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.

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.

@kayakyakr
Copy link
Contributor

publishing the package to npm would probably solve these type issues, but this helps for now.

@kronkm
Copy link
Author

kronkm commented Sep 2, 2022

@yusinto tagging you for review! For some reason I can't edit the assignees

@yusinto
Copy link
Contributor

yusinto commented Sep 7, 2022

@kronkm thanks for this! I'll review this soon.

@yusinto
Copy link
Contributor

yusinto commented Sep 7, 2022

stricter tsconfig options

@kronkm are you able to share your strict tsconfig.json so I can reproduce these errors please? We have some work to improve the build for this remix sdk to make it more consumable and I want to make sure these PR is in line with that. Thank you.

@kronkm
Copy link
Author

kronkm commented Sep 7, 2022

stricter tsconfig options

@kronkm are you able to share your strict tsconfig.json so I can reproduce these errors please? We have some work to improve the build for this remix sdk to make it more consumable and I want to make sure these PR is in line with that. Thank you.

Sure thing! Here ya go, and running "typescript": "^4.6.4":

{
    "include": ...,
    "exclude": ...,
    "compilerOptions": {
        "lib": ["DOM", "DOM.Iterable", "ES2019"],
        "isolatedModules": true,
        "esModuleInterop": true,
        "jsx": "react-jsx",
        "module": "esnext",
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "target": "ES2019",
        "skipLibCheck": true,
        "allowJs": true,
        "checkJs": false,
        "strict": true,
        "baseUrl": ".",
        "paths": {
            "~/*": ["./app/*"]
        },
        // Type checking rules and constraints
        "allowSyntheticDefaultImports": true,
        "forceConsistentCasingInFileNames": true,
        "noFallthroughCasesInSwitch": true,
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "strictFunctionTypes": true,
        "strictNullChecks": true,
        // Remix takes care of building everything in `remix build`.
        "noEmit": true
    }
}

@yusinto
Copy link
Contributor

yusinto commented Sep 14, 2022

@kronkm these are issues arising due to your application consuming the src files directly. If you run yarn build at the root of the repo, this will run typescript and produce a lib folder. This lib folder should be the one your application references when importing the remix sdk. The remix-sdk package.json specifies explicit exports that maps to this lib folder. You should be able to import the remix-sdk's exports like the example app:

// this 
import { useFlags } from 'remix-sdk/client';

This way most of the errors you see should go away. Please note we are seeing these errors because it's hard to use the remix-sdk because it's not published on npm yet. Once published, these problems should also go away. We hope to do this soon.

This was referenced Jan 30, 2023
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.

3 participants