node-win32-api icon indicating copy to clipboard operation
node-win32-api copied to clipboard

Types derived from HANDLE do not work and default to any

Open altxt2 opened this issue 9 months ago • 2 comments

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 -y
  • npm install typescript @types/node win32-def
  • node_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.ts in VS Code and hover mouse over testVar
  • node_modules\.bin\tsc --noEmit

Expected outcome

  • type of testVar is HANDLE or number or similar
  • tsc produces no errors

Actual outcome

  • type of testVar is any
  • tsc produces 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

altxt2 avatar Feb 25 '25 11:02 altxt2

Thanks

waitingsong avatar Feb 26 '25 09:02 waitingsong

Fixed by https://github.com/waitingsong/node-win32-api/releases/tag/v26.1.2

waitingsong avatar Feb 26 '25 09:02 waitingsong