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"] +}