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.
This commit is contained in:
theridgerugby 2026-10-21 23:56:12 -04:00
parent 23d7bfc8ba
commit 67f59fab67
5 changed files with 23 additions and 1 deletions

6
node.d.ts vendored
View File

@ -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

View File

@ -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": {

View File

@ -0,0 +1 @@
Raw text fixture.

View File

@ -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

View File

@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"],
"noUncheckedSideEffectImports": true
},
"include": ["./node-imports.ts"]
}