Skip to content

chore!: bump TypeScript target and lib to ES2022 - #333

Merged
cryptodev-2s merged 2 commits into
mainfrom
migrate/es2022
Sep 10, 2026
Merged

chore!: bump TypeScript target and lib to ES2022#333
cryptodev-2s merged 2 commits into
mainfrom
migrate/es2022

Conversation

@cryptodev-2s

@cryptodev-2s cryptodev-2s commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Top of stack #331, on #325. Mirrors MetaMask/core#10019, the last of core's foundational chain.

Before After
target ES2020 ES2022
lib ["ES2020", "DOM"] ["ES2022", "DOM"]

Correctly last in the order: raising the emit target is only defensible once the Node floor guarantees the runtime supports it, which #328 established.

It is not cosmetic

wrapError sets cause behind two @ts-ignore comments, with this note in the source:

Error causes are not supported by our current tsc target (ES2020, we need ES2022 to make this work)

Error.cause is ES2022, so both suppressions are now obsolete and are removed. The types are genuine rather than ignored.

The evidence came from enabling test type checking: with lib: ES2020 a tsc pass over the tests reports 11 errors, nearly all Property 'cause' does not exist. With lib: ES2022 it reports zero. That is why the type checking PR stacks on top of this one rather than below it.

Verification

Build, tests, tsd, eslint and lint all pass.


Note

Medium Risk
Breaking for consumers on older runtimes or TS configs that assumed ES2020 output; error utilities are widely used but the change is configuration and type hygiene rather than new logic.

Overview
BREAKING: Raises the TypeScript target and lib from ES2020 to ES2022, so published output expects a modern runtime or bundler that can consume ES2022. The unreleased changelog documents this alongside the existing Node/ESM breaking changes.

In wrapError, the Error(message, { cause }) path no longer needs @ts-ignore or the comment about ES2020 lacking Error.cause types—ES2022 lib makes cause a first-class typed option.

No runtime behavior change in wrapError beyond what was already implemented; this is primarily a compile/emit floor and type-checking cleanup that unblocks stricter test tsc (e.g. cause on errors) in follow-up work.

Reviewed by Cursor Bugbot for commit 6242b3e. Bugbot is set up for automated code reviews on this repo. Configure here.

@cryptodev-2s
cryptodev-2s added this pull request to stack #331 September 9, 2026 20:38
Comment thread CHANGELOG.md Outdated
Comment on lines +12 to +13
- **BREAKING:** Bump the TypeScript `target` and `lib` to `ES2022` ([#332](https://github.com/MetaMask/utils/pull/332))
- Emitted output now uses ES2022 syntax, matching core. Consumers on the supported Node range are unaffected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
- **BREAKING:** Bump the TypeScript `target` and `lib` to `ES2022` ([#332](https://github.com/MetaMask/utils/pull/332))
- Emitted output now uses ES2022 syntax, matching core. Consumers on the supported Node range are unaffected.
- **BREAKING:** Bump TypeScript target to ES2022 ([#332](https://github.com/MetaMask/utils/pull/332))
- This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done here 475c5c9

Base automatically changed from migrate/pr2k-typescript to main September 10, 2026 13:50
@cryptodev-2s
cryptodev-2s merged commit 358c630 into main Sep 10, 2026
19 checks passed
@cryptodev-2s
cryptodev-2s deleted the migrate/es2022 branch September 10, 2026 13:54
cryptodev-2s added a commit that referenced this pull request Sep 10, 2026
Top of stack #331, on #333. Opts this package into the progressive test
type checking rollout core is doing (16 of its 100 packages so far).

## Tests were not type checked at all

Verified by injecting `const deliberateTypeError: number = "a string"`
into a test file:

| Check | Result |
| --- | --- |
| `yarn build` | passes, `tsconfig.build.json` excludes tests |
| `yarn test:source` | passes, see below |
| `yarn test:types` | passes, tsd only reads `*.test-d.ts` |
| `yarn lint` | passes |

`test:source` can never catch it: `isolatedModules` puts ts-jest on its
`transpileModule` path, which erases types without checking them.

## The change

```
lint:tsc = tsc --noEmit --project tsconfig.lint.json     ← added to `lint`
```

`tsconfig.lint.json` extends `tsconfig.json` (which already covers
everything the build does not) and adds `skipLibCheck`, because
dependency declarations do not satisfy the strict flags used here.

## Why `*.test-d.ts` is excluded

Those belong to `tsd`, which checks them itself via `yarn test:types`
(fixed in #322). Including them here pulls `tsd`'s own types into the
program, and those reach `type-fest`, whose `basic.d.ts` carries `///
<reference lib="esnext" />`. That silently widens built in types past
this package's `lib`, producing a spurious failure where `FrozenSet` no
longer satisfies `ReadonlySet` because of Set methods we do not target.
Traced with `tsc --explainFiles`.

## Why this stacks on ES2022

With `lib: ES2020` a `tsc` pass over the tests reports **11 errors**,
nearly all `Property 'cause' does not exist`. With `lib: ES2022`,
**zero**. #333 has to land first.

## Confirmed not vacuous

A deliberate type error in a test file now exits non-zero with `TS2322`,
and `tsd` still independently catches a bad `expectAssignable` in a
`.test-d.ts` file.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Dev-only lint and TypeScript config changes; no runtime or shipped
library behavior changes.
> 
> **Overview**
> **`yarn lint` now runs TypeScript on test and other non-build code**
through a new `lint:tsc` script, closing a gap where
`tsconfig.build.json` and transpile-only Jest never validated types in
`*.test.ts` files.
> 
> A new **`tsconfig.lint.json`** extends the root config with
`skipLibCheck`, incremental **`emitDeclarationOnly`** output under
**`.tsc-lint-cache/`** (gitignored and ignored by ESLint), and an
**exclude** for **`*.test-d.ts`** so `tsd`-owned type tests are not
double-checked or polluted by `tsd`’s wider `lib` types.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
670fa8a. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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