hazelcast-nodejs-client icon indicating copy to clipboard operation
hazelcast-nodejs-client copied to clipboard

Typescript Build Error

Open marinrusu1997 opened this issue 3 years ago • 5 comments

Describe the bug When building application that uses hazelcast-client with Typescript compiler the following error is thrown:

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:7:5 - error TS2411: Property 'added' of type 'EntryEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

7     added?: EntryEventListener<K, V>;
      ~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:8:5 - error TS2411: Property 'removed' of type 'EntryEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

8     removed?: EntryEventListener<K, V>;
      ~~~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:9:5 - error TS2411: Property 'updated' of type 'EntryEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

9     updated?: EntryEventListener<K, V>;
      ~~~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:10:5 - error TS2411: Property 'merged' of type 'EntryEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

10     merged?: EntryEventListener<K, V>;
       ~~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:11:5 - error TS2411: Property 'evicted' of type 'EntryEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

11     evicted?: EntryEventListener<K, V>;
       ~~~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:12:5 - error TS2411: Property 'expired' of type 'EntryEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

12     expired?: EntryEventListener<K, V>;
       ~~~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:13:5 - error TS2411: Property 'loaded' of type 'EntryEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

13     loaded?: EntryEventListener<K, V>;
       ~~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:14:5 - error TS2411: Property 'mapEvicted' of type 'MapEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

14     mapEvicted?: MapEventListener<K, V>;
       ~~~~~~~~~~

node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:15:5 - error TS2411: Property 'mapCleared' of type 'MapEventListener<K, V> | undefined' is not assignable to 'string' index type 'EntryEventListener<K, V> | MapEventListener<K, V>'.

15     mapCleared?: MapEventListener<K, V>;
       ~~~~~~~~~~


Found 9 errors in the same file, starting at: node_modules/hazelcast-client/lib/proxy/EntryListener.d.ts:7

Expected behavior Build should pass without errors.

Screenshots image

Environment (please complete the following information):

  1. Client version 5.1.0

  2. Node.js version 14.19.3

  3. Typescript version 4.7.3

  4. Operating system: MacOS Monterey 12.13.1

Additional context tsconfig.json

{
  "compilerOptions": {
    "allowJs": false,
    "checkJs": false,

    "incremental": true,
    "composite": false,

    "declaration": false,
    "declarationMap": false,

    "resolveJsonModule": true,
    "allowUmdGlobalAccess": false,

    "module": "ESNext",
    "moduleResolution": "Node",
    "target": "ESNext",
    "lib": ["ESNext"],
    "plugins": [
      {
        "transform": "@zoltu/typescript-transformer-append-js-extension/output/index.js",
        "after": true
      }
    ],

    "allowSyntheticDefaultImports": true,

    "removeComments": false,
    "sourceMap": false,

    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "alwaysStrict": true,
    "exactOptionalPropertyTypes": false,
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitOverride": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noPropertyAccessFromIndexSignature": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,

    "strict": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "useUnknownInCatchVariables": false,

    "disableSizeLimit": true,

    "esModuleInterop": true,

    "forceConsistentCasingInFileNames": true,

    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

marinrusu1997 avatar Jun 15 '22 15:06 marinrusu1997

Hi I did not get a compilation error with this code:

import {Client} from "hazelcast-client";

async function main() {
    const client = await Client.newHazelcastClient();
    const aMap = await client.getMap("a");
    await aMap.addEntryListener({
        added: (entryEvent) => {
            console.log(entryEvent)
        }
    })
    await client.shutdown();
}

main().catch(err => {
    console.error(err);
    process.exit(1);
});

with exactly your setup except I am on linux. But I see some errors in the IDE in type definition file EntryListener.d.ts:

image

Recently we fixed this issue in https://github.com/hazelcast/hazelcast-nodejs-client/pull/1294 as a fix to another issue. So, it will be in the next release. I think we should release a patch version for this fix. Let me try to plan it as well.

srknzl avatar Jun 15 '22 16:06 srknzl

Interesting part is that I didn't even used addEntryListener API, nor this interface ... A patch would be definitively helpful, because build on CI is failing.

On my local machine I applied the following hot fix and the build succeeds:

[event: string]: EntryEventListener<K, V> | MapEventListener<K, V> | undefined;

marinrusu1997 avatar Jun 15 '22 16:06 marinrusu1997

You may get away from the error for now by setting skipLibCheck to true as mentioned in https://github.com/hazelcast/hazelcast-nodejs-client/issues/1286#issuecomment-1121586700

srknzl avatar Jun 15 '22 16:06 srknzl

Ok. Thank you.

marinrusu1997 avatar Jun 15 '22 16:06 marinrusu1997

I got an error as well. I was using npx tsc index.ts therefore not getting an error. npx tsc lead to an error for me as well. Even with simple script like this:

import {Client} from "hazelcast-client";

console.log(Client);

So I am able to reproduce your problem now.

srknzl avatar Jun 16 '22 09:06 srknzl

The issue is fixed. Next release will include it. (a release from maintenance branches or master)

srknzl avatar Sep 29 '22 10:09 srknzl