Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Fix] correct generated type declaration #3840

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

ocavue
Copy link
Contributor

@ocavue ocavue commented Oct 12, 2024

Closes #3838

This PR fixes various issues in the generated index.d.ts. The full diff for index.d.ts can be viewed in this link. The change highlight are shown below:

  rules: {
-   'react/display-name': number;
+   'react/display-name': 2;
-   'react/jsx-key': number;
+   'react/jsx-key': 2;
    'jsx-no-duplicate-props': import("eslint").Rule.RuleModule;
    'jsx-no-leaked-render': import("eslint").Rule.RuleModule;
-   'jsx-no-literals': {
-      meta: import("eslint").Rule.RuleMetaData;
-      create(context: any): (false & {
-      ...
-   };
+   'jsx-no-literals': import("eslint").Rule.RuleModule;

- Add types/rules/jsx-no-literals.d.ts to avoid error TS2309: An export assignment cannot be used in a module with other exported elements.
Copy link

codecov bot commented Oct 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.67%. Comparing base (4ef92b4) to head (ade24b6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3840      +/-   ##
==========================================
+ Coverage   97.61%   97.67%   +0.06%     
==========================================
  Files         133      136       +3     
  Lines        9959     9979      +20     
  Branches     3694     3699       +5     
==========================================
+ Hits         9721     9747      +26     
+ Misses        238      232       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ljharb
Copy link
Member

ljharb commented Oct 16, 2024

ok, i fixed the issue with index.js in master, but i've rebased this PR on top of that, since this is probably a better outcome still :-)

@ocavue
Copy link
Contributor Author

ocavue commented Oct 17, 2024

@ljharb Hi. Thanks for your review. I've addressed all your previous comments.

In addition to that, I was thinking why we have issues like #3838 even if we have .github/workflows/type-check.yml to check the built types. I found there are three issues in the CI workflow and I fixed them.

  1. In test-published-types/index.js, to make the typescript to check the type, we need to create a variable first and export it later
// Bad
/** @type {import('eslint').Linter.Config[]} */
module.exports = [ ... ] 

// Good
/** @type {import('eslint').Linter.Config[]} */
const config = [ ... ]
module.exports = config;
  1. In test-published-types/package.json, if we use "eslint-plugin-react": "file:..", we would copy/link all node_modules under eslint-plugin-react to test-published-types/node_modules/eslint-plugin-react/node_modules. This is problematic because test-published-types use the built-in types from the latest eslint, while eslint-plugin-react use the deprecated @types/eslint. They have conflict.

    I fixed this by packing eslint-plugin-react into a .taz file and install it later. By doing that, @types/eslint, which is a dev dependency of eslint-plugin-react, won't be installed under test-published-types.

  2. There is a small issue in the eslint's type declarations:

$ cd test-published-types
$ npx tsc --lib es2015
   
node_modules/eslint/lib/types/index.d.ts:928:81 - error TS2574: A rest element type must be an array type.

928     type RuleSeverityAndOptions<Options extends any[] = any[]> = [RuleSeverity, ...Partial<Options>];
                                                                                    ~~~~~~~~~~~~~~~~~~~

I need to fix it by adding "skipLibCheck": false in test-published-types/tsconfig.json.

@burtek
Copy link
Contributor

burtek commented Nov 26, 2024

Any updates on this? 👀

@ljharb ljharb force-pushed the ocavue/types branch 2 times, most recently from ade24b6 to e80def4 Compare November 27, 2024 07:14
@ljharb ljharb merged commit e80def4 into jsx-eslint:master Nov 27, 2024
402 checks passed
@karlhorky karlhorky mentioned this pull request Nov 27, 2024
2 tasks
cswimr pushed a commit to cswimr/gauntlet-cswimr-plugins that referenced this pull request Dec 27, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) | devDependencies | patch | [`7.37.2` -> `7.37.3`](https://renovatebot.com/diffs/npm/eslint-plugin-react/7.37.2/7.37.3) |

---

### Release Notes

<details>
<summary>jsx-eslint/eslint-plugin-react (eslint-plugin-react)</summary>

### [`v7.37.3`](https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/CHANGELOG.md#7373---20241223)

[Compare Source](jsx-eslint/eslint-plugin-react@v7.37.2...v7.37.3)

##### Fixed

-   \[`no-danger`]: avoid a crash on a nested component name ([#&#8203;3833][] [@&#8203;ljharb](https://github.com/ljharb))
-   \[Fix] types: correct generated type declaration ([#&#8203;3840][] [@&#8203;ocavue](https://github.com/ocavue))
-   \[`no-unknown-property`]: support `precedence` prop in react 19 ([#&#8203;3829][] [@&#8203;acusti](https://github.com/acusti))
-   \[`prop-types`]: props missing in validation when using generic types from a namespace import ([#&#8203;3859][] [@&#8203;rbondoc96](https://github.com/rbondoc96))

##### Changed

-   \[Tests] \[`jsx-no-script-url`]: Improve tests ([#&#8203;3849][] [@&#8203;radu2147](https://github.com/radu2147))
-   \[Docs] fix broken links: \[`default-props-match-prop-types`], \[`jsx-boolean-value`], \[`jsx-curly-brace-presence`], \[`jsx-no-bind`], \[`no-array-index-key`], \[`no-is-mounted`], \[`no-render-return-value`], \[`require-default-props`] ([#&#8203;3841][] [@&#8203;bastiendmt](https://github.com/bastiendmt))

[7.37.3]: jsx-eslint/eslint-plugin-react@v7.37.2...v7.37.3

[#&#8203;3859]: jsx-eslint/eslint-plugin-react#3859

[#&#8203;3849]: jsx-eslint/eslint-plugin-react#3849

[#&#8203;3841]: jsx-eslint/eslint-plugin-react#3841

[#&#8203;3840]: jsx-eslint/eslint-plugin-react#3840

[#&#8203;3833]: jsx-eslint/eslint-plugin-react#3833

[#&#8203;3829]: jsx-eslint/eslint-plugin-react#3829

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS44My40IiwidXBkYXRlZEluVmVyIjoiMzkuODMuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://www.coastalcommits.com/cswimr/gauntlet-cswimr-plugins/pulls/9
Co-authored-by: Renovate <renovate@coastalcommits.com>
Co-committed-by: Renovate <renovate@coastalcommits.com>
@voxpelli
Copy link
Contributor

voxpelli commented Jan 8, 2025

Great work! 🙏

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: TS types are broken
5 participants