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: Upgrade typescript configuration #91

Merged
merged 2 commits into from
Jan 6, 2025
Merged

fix: Upgrade typescript configuration #91

merged 2 commits into from
Jan 6, 2025

Conversation

just-boris
Copy link
Member

@just-boris just-boris commented Dec 26, 2024

Issue #, if available:

Notes

Align configuration with cloudscape-design/components and fix some build issues

Testing

Dry-runs: 7169913711, 7169914866

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

codecov bot commented Dec 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.21%. Comparing base (7af5676) to head (d6a57e3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #91   +/-   ##
=======================================
  Coverage   99.21%   99.21%           
=======================================
  Files          14       14           
  Lines         509      509           
  Branches      180      180           
=======================================
  Hits          505      505           
  Misses          4        4           

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

@@ -12,6 +12,7 @@
"test-08:00": "TZ=America/Los_Angeles vitest --run ./src/__tests__/date-utils --coverage=false",
"test+08:00": "TZ=Asia/Brunei vitest --run ./src/__tests__/date-utils --coverage=false",
"test-local": "vitest --run",
"pretest": "tsc -p tsconfig.unit.json",
Copy link
Member Author

Choose a reason for hiding this comment

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

Regression happened when migrating to vitest: #73

Unlike ts-jest, vitest does not do type checks when running. Added this step and fixed a bunch of type errors existed in the project

@@ -1,7 +1,7 @@
{
"name": "@cloudscape-design/collection-hooks",
"version": "1.0.0",
"lockfileVersion": 2,
"lockfileVersion": 3,
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we use node.js 20, the lockfile must be version 3

@@ -58,12 +59,13 @@
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-unicorn": "^11.0.2",
"husky": "^9.0.0",
"jsdom": "^25.0.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike Jest, in Vitest there is no special "environment" package, but it expects JSDOM to be installed as a dependency. Before this change, it relied on the implicit version appeared in package-lock file, now it is explicit

Comment on lines -3 to +9
"target": "es5",
"target": "es2015",
"module": "esnext",
"declaration": true,
"types": [],
"esModuleInterop": true,
"moduleResolution": "Node",
"lib": ["es5", "es2015.collection"],
"lib": ["es2020"],
Copy link
Member Author

Choose a reason for hiding this comment

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

Pulling changes from the main components config

  1. Bump target and lib to es2015/es2020 respectively
  2. Set types: []. The typescript default is "load everything from the node_modules/@types directory" which we do not want. We only want the types listed in the lib section

* subset of node.js types, safe to use in browser and bundlers
*/
declare const process: { env: { NODE_ENV?: string } };
declare const console: { warn: (...args: Array<any>) => void };
Copy link
Member Author

Choose a reason for hiding this comment

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

Since we do not load neither @types/node or dom in our code, need to provide shims for this API.

(Fun fact, console object is not a part of Javascript spec, it is separately described in Node and DOM specs)

Copy link
Member

Choose a reason for hiding this comment

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

why not install the types?

Copy link
Member Author

Choose a reason for hiding this comment

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

Which types?

dom types would undermine SSR support, require to write more compatibility tests
@types/node would undermine browser support, potentially causing issues when bundling

so, let's keep it a narrow manually-managed list. I do not expect this list to grow more than that (only setTimeout comes to mind as another "node or dom" type we might need)

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks. I think the SSR support reasoning can be added as a code comment, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

@@ -1,7 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": ["es2019", "dom"],
"lib": ["es2020", "dom"],
"moduleResolution": "bundler",
Copy link
Member Author

Choose a reason for hiding this comment

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

There is an issue when running type checks for test files. Vitest does not pass type checks unless moduleResolution: bundler is used: vitest-dev/vitest#4567

Needed to upgrade typescript for this as well

@just-boris just-boris marked this pull request as ready for review January 3, 2025 21:45
@just-boris just-boris requested a review from a team as a code owner January 3, 2025 21:45
@just-boris just-boris requested review from pan-kot and removed request for a team January 3, 2025 21:45
pan-kot
pan-kot previously approved these changes Jan 6, 2025
* subset of node.js types, safe to use in browser and bundlers
*/
declare const process: { env: { NODE_ENV?: string } };
declare const console: { warn: (...args: Array<any>) => void };
Copy link
Member

Choose a reason for hiding this comment

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

why not install the types?

@just-boris just-boris added this pull request to the merge queue Jan 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Jan 6, 2025
@just-boris just-boris added this pull request to the merge queue Jan 6, 2025
Merged via the queue into main with commit 5ae4cc5 Jan 6, 2025
36 checks passed
@just-boris just-boris deleted the es-target branch January 6, 2025 13:11
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.

2 participants