Skip to content

Fix TypeScript config #2029

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

Merged
merged 7 commits into from
Jun 11, 2025
Merged

Fix TypeScript config #2029

merged 7 commits into from
Jun 11, 2025

Conversation

westonruter
Copy link
Member

When reviewing #2025, I noticed in PhpStorm that some of the types were undefined:

image

Nevertheless, running npm run tsc didn't fail with an error.

It turns out this was due to a misconfiguration in in the tsconfig.json, due to a mistake by me in 5b97111 as part of #2006.

With the fix to the config, these are the errors now uncovered, including the yet-unreleased View Transitions plugin.

bin/plugin/commands/changelog.js:27:39 - error TS2694: Namespace '"/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index"' has no exported member 'IssuesListForRepoResponseItem'.

27 /** @typedef {import('@octokit/rest').IssuesListForRepoResponseItem} IssuesListForRepoResponseItem */
                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bin/plugin/commands/changelog.js:164:11 - error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

164    return a - b;
              ~

bin/plugin/commands/changelog.js:164:15 - error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.

164    return a - b;
                  ~

bin/plugin/commands/changelog.js:213:51 - error TS2345: Argument of type 'Octokit & RestEndpointMethods & Api & { paginate: PaginateInterface; }' is not assignable to parameter of type 'typeof import("/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index", { with: { "resolution-mode": "import" } })'.
  Property 'Octokit' is missing in type 'Octokit & RestEndpointMethods & Api & { paginate: PaginateInterface; }' but required in type 'typeof import("/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index", { with: { "resolution-mode": "import" } })'.

213  const pullRequests = await fetchAllPullRequests( octokit, settings );
                                                      ~~~~~~~

  node_modules/@octokit/rest/dist-types/index.d.ts:6:22
    6 export declare const Octokit: typeof Core & Constructor<ReturnType<typeof legacyRestEndpointMethods> & {
                           ~~~~~~~
    'Octokit' is declared here.

bin/plugin/config.js:14:2 - error TS2353: Object literal may only specify known properties, and 'textDomain' does not exist in type 'WPPluginCLIConfig'.

14  textDomain: 'performance-lab',
    ~~~~~~~~~~

bin/plugin/lib/logger.js:4:9 - error TS2305: Module '"node:util"' has no exported member 'styleText'.

4 const { styleText } = require( 'node:util' );
          ~~~~~~~~~

bin/plugin/lib/milestone.js:2:39 - error TS2694: Namespace '"/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index"' has no exported member 'IssuesListForRepoResponseItem'.

2 /** @typedef {import('@octokit/rest').IssuesListForRepoResponseItem} IssuesListForRepoResponseItem */
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bin/plugin/lib/milestone.js:3:39 - error TS2694: Namespace '"/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index"' has no exported member 'IssuesListMilestonesForRepoResponseItem'.

3 /** @typedef {import('@octokit/rest').IssuesListMilestonesForRepoResponseItem} OktokitIssuesListMilestonesForRepoResponseItem */
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bin/plugin/lib/milestone.js:20:26 - error TS2339: Property 'issues' does not exist on type 'typeof import("/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index", { with: { "resolution-mode": "import" } })'.

20  const options = octokit.issues.listMilestones.endpoint.merge( {
                            ~~~~~~

bin/plugin/lib/milestone.js:27:58 - error TS2694: Namespace '"/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index"' has no exported member 'Response'.

27   * @type {AsyncIterableIterator<import('@octokit/rest').Response<import('@octokit/rest').IssuesListMilestonesForRepoResponse>>}
                                                            ~~~~~~~~

bin/plugin/lib/milestone.js:29:28 - error TS2339: Property 'paginate' does not exist on type 'typeof import("/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index", { with: { "resolution-mode": "import" } })'.

29  const responses = octokit.paginate.iterator( options );
                              ~~~~~~~~

bin/plugin/lib/milestone.js:63:26 - error TS2339: Property 'issues' does not exist on type 'typeof import("/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index", { with: { "resolution-mode": "import" } })'.

63  const options = octokit.issues.listForRepo.endpoint.merge( {
                            ~~~~~~

bin/plugin/lib/milestone.js:74:58 - error TS2694: Namespace '"/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index"' has no exported member 'Response'.

74   * @type {AsyncIterableIterator<import('@octokit/rest').Response<import('@octokit/rest').IssuesListForRepoResponse>>}
                                                            ~~~~~~~~

bin/plugin/lib/milestone.js:76:28 - error TS2339: Property 'paginate' does not exist on type 'typeof import("/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index", { with: { "resolution-mode": "import" } })'.

76  const responses = octokit.paginate.iterator( options );
                              ~~~~~~~~

bin/plugin/lib/milestone.js:79:36 - error TS2694: Namespace '"/Users/westonruter/repos/wordpress-develop/src/wp-content/plugins/performance/node_modules/@octokit/rest/dist-types/index"' has no exported member 'IssuesListForRepoResponse'.

79   * @type {import('@octokit/rest').IssuesListForRepoResponse}
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~

plugins/view-transitions/js/view-transitions.js:35:32 - error TS2339: Property 'animations' does not exist on type 'ViewTransitionsConfig'.

35   const globalEntries = config.animations[ transitionType ]
                                  ~~~~~~~~~~

plugins/view-transitions/js/view-transitions.js:46:11 - error TS2339: Property 'animations' does not exist on type 'ViewTransitionsConfig'.

46    config.animations[ transitionType ].usePostTransitionNames &&
             ~~~~~~~~~~


Found 17 errors in 5 files.

Errors  Files
     4  bin/plugin/commands/changelog.js:27
     1  bin/plugin/config.js:14
     1  bin/plugin/lib/logger.js:4
     9  bin/plugin/lib/milestone.js:2
     2  plugins/view-transitions/js/view-transitions.js:35

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] View Transitions Issues for the View Transitions plugin labels Jun 2, 2025
Copy link

codecov bot commented Jun 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.06%. Comparing base (05444d4) to head (736473b).
Report is 30 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk    #2029   +/-   ##
=======================================
  Coverage   68.06%   68.06%           
=======================================
  Files          92       92           
  Lines        7626     7626           
=======================================
  Hits         5191     5191           
  Misses       2435     2435           
Flag Coverage Δ
multisite 68.06% <ø> (ø)
single 37.03% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@westonruter westonruter added no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs labels Jun 2, 2025
@westonruter
Copy link
Member Author

There are now 3 files which have issues needing to be addressed:

Found 15 errors in 3 files.

Errors  Files
     4  bin/plugin/commands/changelog.js:27
     9  bin/plugin/lib/milestone.js:2
     2  plugins/view-transitions/js/view-transitions.js:35

@westonruter
Copy link
Member Author

I'm signing off for tonight, so anyone feel free to pick this up.

Comment on lines 1 to 6
export interface ViewTransitionAnimationConfig {
useGlobalTransitionNames: boolean;
usePostTransitionNames: boolean;
}

export interface ViewTransitionsConfig {
Copy link
Member

Choose a reason for hiding this comment

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

Why interface instead of type?

Copy link
Member

Choose a reason for hiding this comment

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

FYI I fixed this in 95d0b4d because it's a bug specific to that plugin. For now I used type for consistency, we can reconsider later / as part of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've resolved the conflict by going with type.

@swissspidy Is there a specific reason you wanted to go with interface instead?

Copy link
Member

Choose a reason for hiding this comment

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

Typically you'd want to use interface for primitives, and types for things like unions, intersections, and aliases. It's also the general practice in the GB code base as well.

I don't see how interface would cause any conflicts but don't have a strong opinion here. Use whatever :)

Copy link
Member

Choose a reason for hiding this comment

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

I've seen various takes on that, don't have an opinion really, just not sure what's best. What I recollect reading about this was that it doesn't really matter and "just choose one and stick with it".

@westonruter westonruter marked this pull request as ready for review June 2, 2025 20:22
Copy link

github-actions bot commented Jun 2, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <[email protected]>
Co-authored-by: swissspidy <[email protected]>
Co-authored-by: felixarntz <[email protected]>
Co-authored-by: ShyamGadde <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter
Copy link
Member Author

With some help from Gemini 2.5 Pro, I've addressed the remaining issues related to Octokit typing.

@westonruter westonruter removed the [Plugin] View Transitions Issues for the View Transitions plugin label Jun 2, 2025
@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2025 Jun 2, 2025
@westonruter westonruter moved this from Not Started/Backlog 📆 to Code Review 👀 in WP Performance 2025 Jun 2, 2025
@westonruter westonruter requested review from ShyamGadde and b1ink0 June 11, 2025 03:29
@westonruter westonruter merged commit 77d137f into trunk Jun 11, 2025
23 checks passed
@westonruter westonruter deleted the fix/tsc branch June 11, 2025 13:57
@github-project-automation github-project-automation bot moved this from Code Review 👀 to Done 😃 in WP Performance 2025 Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no milestone PRs that do not have a defined milestone for release skip changelog PRs that should not be mentioned in changelogs [Type] Bug An existing feature is broken
Projects
Status: Done 😃
Development

Successfully merging this pull request may close these issues.

4 participants