Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[email protected]: crypto declarations require a global CryptoKey type, breaking Node-only type-checks with @types/node 22 and 24

クローズ
#10,196 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@effect-bot がすでに取り組んでいます。

2026年10月30日 から。

  • #10197 @effect-bot による — オープン

評価

この issue はまだ評価されていません。

説明

bug
What version of Effect is running?

4.1.0, also main at 0b4cfbc. Not reproducible with 4.0.7

What steps can reproduce the bug?

Any effect import fails to type-check with @types/node 22 or 24, no DOM library and skipLibCheck: false. This is the configuration from #8745 and #10115, with older Node types. #10116 fixes JsonWebKey but leaves these errors

Create these files in an otherwise empty directory

package.json:

{
  "private": true,
  "type": "module",
  "dependencies": {
    "effect": "4.1.0"
  },
  "devDependencies": {
    "@types/node": "24.19.2",
    "typescript": "7.0.2"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2024",
    "module": "NodeNext",
    "lib": ["ES2024"],
    "types": ["node"],
    "strict": true,
    "noEmit": true
  },
  "include": ["src/**/*.ts"]
}

src/repro.ts:

import type * as Effect from "effect/Effect"

export type Probe = Effect.Effect<void>

Run:

pnpm install
pnpm exec tsc --project tsconfig.json

On 4.1.0 this also fails with TypeScript 6.0.3 and 5.9.3. Tested on Node.js 24.22.1

What is the expected behavior?

The import type-checks with Node's declarations, as it does on 4.0.7

Effect's README lists Node.js 22.19 or newer as supported and no DOM requirement, so @types/node 22 and 24 are expected to work

What do you see instead?
node_modules/.pnpm/[email protected]/node_modules/effect/dist/crypto/Aead.d.ts(306,81): error TS2749: 'CryptoKey' refers to a value, but is being used as a type here. Did you mean 'typeof CryptoKey'?

The same error appears at Cipher.d.ts(219,84), KeyAgreement.d.ts(291,94), KeyAgreement.d.ts(306,93), KeyWrap.d.ts(341,80), KeyWrap.d.ts(357,92), KeyWrap.d.ts(372,91), Mac.d.ts(232,84), Signature.d.ts(415,94) and Signature.d.ts(430,93). 4.1.0 also reports the JsonWebKey error from #10115

Effect @types/node Result, with TypeScript 7.0.2
4.0.7 24.19.2 Passes
4.1.0 24.19.2 10 CryptoKey errors and the JsonWebKey error
main at 0b4cfbc, from pkg.pr.new 22.20.5 10 errors, TS2304 Cannot find name 'CryptoKey'
main at 0b4cfbc, from pkg.pr.new 24.19.2 10 CryptoKey errors
main at 0b4cfbc, from pkg.pr.new 25.9.9 Passes
main at 0b4cfbc, from pkg.pr.new 26.6.6 Passes

The fromCryptoKey, privateKeyFromCryptoKey and publicKeyFromCryptoKey constructors take the global CryptoKey type. TypeScript's DOM library declares it. @types/node 24 declares a global CryptoKey value and a webcrypto.CryptoKey type inside node:crypto, but no global type

The error occurs with Effect alone, without using any crypto API. Adding DOM to lib, enabling skipLibCheck, or the workaround below makes the reproduction pass

Additional information

The root package.json uses @types/node ^26.6.5 and the base tsconfig enables skipLibCheck, so checks in this repository would not show these errors. check.yml does run a Node 24 job for @effect/platform-node

This differs from #9785, which covered specific entry points such as effect/rpc and @effect/platform-node. Here every effect import fails, as in #8745 and #10115

Proposed fix

Declare the shape these constructors accept, as #10116 did for JsonWebKey:

export interface CryptoKeyLike {
  readonly algorithm: { readonly name: string }
  readonly extractable: boolean
  readonly type: "private" | "public" | "secret"
  readonly usages: ReadonlyArray<string>
}

A standalone check passes the key type that crypto.subtle.exportKey accepts into a function taking this interface. It passes with @types/node 22, 24 and 26, each with Node types only, DOM types only and both, under strict and exactOptionalPropertyTypes with TypeScript 7.0.2

Deriving the type with (typeof CryptoKey)["prototype"], the approach from #8838, passes the same check with @types/node 24 and 26. It fails with 22, which has no global CryptoKey

Neither change has been tested inside Effect's own build or test suite

Current workaround

Adding this file under src/ makes the reproduction pass on 4.1.0 with @types/node 24.19.2:

import type { JsonWebKey as NodeJsonWebKey, webcrypto } from "node:crypto"

declare global {
  interface CryptoKey extends webcrypto.CryptoKey {}
  interface JsonWebKey extends NodeJsonWebKey {}
}

[!NOTE]
Posted by Claude Opus 5.5 on behalf of the author

主要言語
TypeScript
スター
16.7k
フォーク
808
平均マージ
10時間 15分
マージ済み PR(30日)
845

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Effect-TS/effect のほかの issue

Effect-TS/effect の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。