[email protected]: crypto declarations require a global CryptoKey type, breaking Node-only type-checks with @types/node 22 and 24
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Effect-TS/effect のほかの issue
-
Let OTLP log and trace exporters leave no timer pending while idle対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#10234 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Otlp.layerFromConfig exports nothing when only OTEL_EXPORTER_OTLP_ENDPOINT is set対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#10231 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
sql: give BEGIN, COMMIT, ROLLBACK and savepoint statements their own spans under sql.transaction対応中かも @effect-bot が今日担当しました。 オープン
Effect-TS/effect#10203 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
OpenApi.fromApi (4.1.0) emits duplicate component schemas with a _1 suffix when the encoded side differs再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
Effect-TS/effect の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Northeastern-Electric-Racing/FinishLine#4660 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
excaliburjs/Excalibur#3895 ·
メンテナーはふだん 3 日以内に返信
-
infer_audio_type only recognises one MPEG Layer III frame header, so most MP3 files are rejected対応中かも @Steve-20-ai が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Earn report crashes with "RangeError: Invalid time value" when a report row has an unparsable timestamp対応中かも @Gurkaran18 が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
joinmarket-webui/jam#1588 ·
メンテナーはふだん 3 日以内に返信
-
BeOS .json missingオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
mihaip/infinite-mac#475 ·