node-win32-api
node-win32-api copied to clipboard
Types derived from HANDLE do not work and default to any
Types derived from HANDLE do not work and default to any, likely due to a missing dependency in win32-def
Steps to reproduce
npm init -ynpm install typescript @types/node win32-defnode_modules\.bin\tsc --init- create
app.ts:import type { HANDLE } from 'win32-def/types' let testVar: HANDLE - edit
tsconfig.json:"module": "nodenext", // or "preserve" "moduleResolution": "nodenext", // or "bundler" "skipLibCheck": false - open
app.tsin VS Code and hover mouse overtestVar node_modules\.bin\tsc --noEmit
Expected outcome
- type of
testVarisHANDLEornumberor similar tscproduces no errors
Actual outcome
- type of
testVarisany tscproduces this:
node_modules/win32-def/src/lib/common.types.ts:6:32 - error TS2307: Cannot find module '@waiting/shared-types' or its corresponding type declarations.
6 import type { BigIntStr } from '@waiting/shared-types'
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/win32-def/src/lib/ffi.types.ts:3:51 - error TS2307: Cannot find module '@waiting/shared-types' or its corresponding type declarations.
3 import type { BigIntStr, MethodTypeUnknown } from '@waiting/shared-types'
~~~~~~~~~~~~~~~~~~~~~~~
node_modules/win32-def/src/lib/types.ts:2:38 - error TS2307: Cannot find module '@waiting/shared-types' or its corresponding type declarations.
2 import type { ToAsyncFunction } from '@waiting/shared-types'
~~~~~~~~~~~~~~~~~~~~~~~
Found 3 errors in 3 files.
Errors Files
1 node_modules/win32-def/src/lib/common.types.ts:6
1 node_modules/win32-def/src/lib/ffi.types.ts:3
1 node_modules/win32-def/src/lib/types.ts:2
Workaround
npm install @waiting/shared-types
Note that there are further type errors in this package, so it's probably best to reset skipLibCheck to true
Thanks
Fixed by https://github.com/waitingsong/node-win32-api/releases/tag/v26.1.2