From 67f59fab6731b02ce5f7acb95db09f012b0a2522 Mon Sep 17 00:00:00 2001 From: theridgerugby <156534506+theridgerugby@users.noreply.github.com> Date: Wed, 21 Oct 2026 23:56:12 -0400 Subject: [PATCH] fix(types): declare raw imports for node consumers Add a *?raw module declaration to electron-vite/node so raw file imports in the main and preload processes are typed as string. Keep runtime behavior unchanged. Add an isolated consumer fixture to pnpm typecheck. Verify that raw imports are strings and reject Buffer assignments so an accidental any declaration cannot pass the regression check. Fixes #893. --- node.d.ts | 6 ++++++ package.json | 2 +- tests/types/fixtures/text.txt | 1 + tests/types/node-imports.ts | 7 +++++++ tests/types/tsconfig.json | 8 ++++++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/types/fixtures/text.txt create mode 100644 tests/types/node-imports.ts create mode 100644 tests/types/tsconfig.json diff --git a/node.d.ts b/node.d.ts index 5ca0f21..7934e31 100644 --- a/node.d.ts +++ b/node.d.ts @@ -10,6 +10,12 @@ declare module '*?modulePath' { export default src } +// raw asset +declare module '*?raw' { + const src: string + export default src +} + // node asset declare module '*?asset' { const src: string diff --git a/package.json b/package.json index f0c4d2a..77194f5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "scripts": { "format": "prettier --write .", "lint": "eslint --cache .", - "typecheck": "tsc --noEmit", + "typecheck": "tsc --noEmit && tsc --noEmit -p tests/types/tsconfig.json", "build": "pnpm run lint && rollup -c rollup.config.ts --configPlugin typescript" }, "simple-git-hooks": { diff --git a/tests/types/fixtures/text.txt b/tests/types/fixtures/text.txt new file mode 100644 index 0000000..8850cc6 --- /dev/null +++ b/tests/types/fixtures/text.txt @@ -0,0 +1 @@ +Raw text fixture. diff --git a/tests/types/node-imports.ts b/tests/types/node-imports.ts new file mode 100644 index 0000000..936e60c --- /dev/null +++ b/tests/types/node-imports.ts @@ -0,0 +1,7 @@ +import 'electron-vite/node' +import raw from './fixtures/text.txt?raw' + +export const text: string = raw + +// @ts-expect-error Raw imports return strings, not Node.js buffers. +export const buffer: Buffer = raw diff --git a/tests/types/tsconfig.json b/tests/types/tsconfig.json new file mode 100644 index 0000000..07a91bb --- /dev/null +++ b/tests/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "types": ["node"], + "noUncheckedSideEffectImports": true + }, + "include": ["./node-imports.ts"] +}