For the purpose of demonstrating my issue, I have set up a demo repository. This repository comprises two projects: electron
and src
, both utilizing TypeScript project references.
In the file src/global.d.ts
, I have defined the type API_TYPE
by importing it from electron/src/index.ts
. Despite this setup, Visual Studio Code (VSCode) fails to correctly determine the actual type of API_TYPE
from src/global.d.ts
. When inspecting the src/main.ts
file in VSCode, a tooltip indicates that the type is unrecognized.
https://i.sstatic.net/vXajk.png
The root of the issue may be linked to the references
field within the tsconfig.json
file. Eliminating the references
field resolves the problem, but doing so is not a viable option as the electron
and src
projects must remain distinct.
Below is the pertinent code excerpt from src/global.d.ts
:
import type { API_TYPE } from "../electron/src/index";
declare global {
interface Window {
electronAPI: PRELOAD_API_TYPE<API_TYPE>;
}
}
export {};
I welcome any suggestions or insights on how to address this matter. Thank you!
Edit at 05-30
A revised version of the demo repository has been uploaded. The earlier demo was fully functional and did not replicate the issue experienced.
Additionally, I have identified that the Vue component is causing the problem. Removing the Vue component src/components/HelloWorld.vue
results in accurate inference of the window.electronAPI type.
Edit at 05-31
An online demo has been re-created, which surprisingly works as expected. However, upon downloading this project to my local machine and opening it in the local VSCode editor, the type inference outcomes are incorrect. Specifically, when hovering over the api
and API_TYPE
variables in the src/main.ts
file, the types are not displayed accurately by the local VSCode.
The following screenshot depicts an online demo exhibiting the correct types. https://i.sstatic.net/8hwGm.png
On the other hand, the subsequent screenshot highlights the discrepancy where the local VSCode editor fails to render the correct types. https://i.sstatic.net/E9TR4.png