node-ffi-napi output parameter @types/ffi-napi missmatch

514 views Asked by At

I have s small test lib with the following code

int test1() {
  return 1;
}

int test2(int* a) {
  *a = 10;
  return 1;
}

Now using this lib in a node (typescript) project complains about wrong types and I have to use as any ... this is working but it seems like a bug in @types/ffi-napi

import { alloc, types, Value } from 'ref-napi';
import { Library } from 'ffi-napi';

const lib = Library('libmy', {
  test1: ['int', []],
  test2: ['int', ['int*']]
});

const res1 = lib.test1();
console.log(`test1() returned ${res1}`);

const res2: Value<number> = alloc(types.int);
lib.test2(res2 as any);

console.log(`test2() returned ${res2.deref()}`);
yarn run v1.22.17
$ tsc && node dist/main.js
test1() returned 1
test2() returned 10
0

There are 0 answers