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

[Code Health][Community Project] Enable TypeScript strict check #1237

Open
huchenlei opened this issue Oct 12, 2024 · 0 comments
Open

[Code Health][Community Project] Enable TypeScript strict check #1237

huchenlei opened this issue Oct 12, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@huchenlei
Copy link
Member

huchenlei commented Oct 12, 2024

Background

Our community project is seeking contributors to help improve our codebase. When we initially migrated to TypeScript, we set the strict option to false to minimize immediate changes. However, we've since discovered that strict type checking is crucial for preventing many bugs, as evidenced by recent pull requests (e.g., #1221, #1199).

To facilitate a gradual transition to strict mode, we've implemented the ts-strict-ignore plugin in PR #1235. This allows us to enable strict type checking one file at a time.

How to Contribute

Step 1: Select a File with // @ts-strict-ignore Header

You can find all files requiring attention using this GitHub code search query.

Alternatively, run npx tsc --strict to see all TypeScript strict mode errors. Consider starting with files that have fewer errors. Example output:

Found 1680 errors in 79 files.
Errors  Files
     4  src/components/common/__tests__/EditableText.spec.ts:16
     1  src/components/common/__tests__/TreeExplorerTreeNode.spec.ts:60
     2  src/components/sidebar/tabs/queue/__tests__/ResultGallery.ts:57
    29  src/extensions/core/clipspace.ts:10
    31  src/extensions/core/colorPalette.ts:86
    ...

Step 2: Remove // @ts-strict-ignore and Run Type Check

  1. Remove the // @ts-strict-ignore comment from your chosen file.
  2. Run npm run typecheck to identify strict mode errors.

Example output:

D:\ComfyUI_frontend [ts_strict13 +0 ~1 -0 !]> npm run typecheck
> comfyui-frontend@1.3.18 typecheck
> tsc --noEmit && tsc-strict
🎯 Found 57 strict files
src/stores/dialogStore.ts(43,9): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
💥 Found 1 error

Step 3: Fix Errors and Submit a Pull Request

Address the identified type errors in your chosen file. Once resolved, submit a pull request with your changes.

For reference, see this example PR: #1236

We appreciate your contribution to improving our project's type safety!

@huchenlei huchenlei added the help wanted Extra attention is needed label Oct 12, 2024
@huchenlei huchenlei pinned this issue Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant