fix: [#1845] Replace ConsoleConstructor import with indexed access type#2095
Conversation
capricorn86
left a comment
There was a problem hiding this comment.
Thank you for your contribution @YevheniiKotyrlo ⭐
|
This reads like a typical LLM pull request. Convinced without doubt to solve an issue but in the end the error is the same as before. |
@Spixmaster I know it was an LLM and I know that it didn't solve #1845, but I guess getting rid of the import is a small improvement (even though it probably didn't have any real effect), so I approved it. |
|
Hey, wanted to follow up on this — my PR didn't actually fix #1845. I was looking at the wrong error (TS2305 from the ConsoleConstructor import) while the real issue was TS2420 (missing interface members). After digging deeper, I found that Bun's type definitions extend the global I've submitted a proper fix in #2102 that adds both methods. Sorry for the confusion on this one. |
Update: This PR fixed the
ConsoleConstructorimport (TS2305) but did not fix the TS2420 reported in #1845 — I misattributed the issue. I should have filed a separate issue for the ConsoleConstructor problem rather than linking it to #1845. The actual fix for #1845 is in #2102.Problem
VirtualConsole.tsimportsConsoleConstructorfrom the Node.js'console'module:This import is emitted into the published
lib/console/VirtualConsole.d.ts, causingTS2305: Module '"console"' has no exported member 'ConsoleConstructor'for consumers whose TypeScript configuration doesn't resolve Node.js built-in module types — for example, projects withskipLibCheck: falseand amoduleResolutionthat doesn't map the'console'specifier to@types/node's console declarations.Reproduction
Any consumer project with
skipLibCheck: falsethat imports something from happy-dom touching VirtualConsole's type will get:This is related to #1845, which reports a similar type compatibility issue with VirtualConsole.
Fix
Replace the
ConsoleConstructorimport with an indexed access typeConsole['Console']. This resolves to the same type (theConsoleproperty on the globalConsoleinterface points toConsoleConstructor) but avoids theimport from 'console'module specifier entirely.Before
After
Verification
npm run compile: passesnpm run lint(root): passes (zero warnings)npm test(packages/happy-dom): all 48 console tests pass. 4 pre-existing failures in unrelated test files (SyncFetch, ModuleURLUtility, BrowserWindow, DetachedWindowAPI) — identical on cleanmaster.skipLibCheck: false: zero ConsoleConstructor errors after fix (confirmedTS2305without fix)