aws / aws-iot-device-sdk-js-v2

Next generation AWS IoT Client SDK for Node.js using the AWS Common Runtime
Apache License 2.0
217 stars 97 forks source link

import * as greengrasscoreipc from 'aws-iot-device-sdk-v2/lib/greengrasscoreipc/client' throws `error TS2769: No overload matches this call.` #374

Closed Xuqing888 closed 1 year ago

Xuqing888 commented 1 year ago

Describe the bug

Hey SDK team:

I hit the:

node_modules/aws-iot-device-sdk-v2/lib/eventstream_rpc_utils.ts:23:24 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'Payload' is not assignable to parameter of type 'WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: "string"): string; }'.
      Type 'ArrayBuffer' is not assignable to type 'WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: "string"): string; }'.

23     return Buffer.from(payload).toString("base64");
                          ~~~~~~~

  node_modules/@types/node/buffer.d.ts:321:13
    321             from(
                    ~~~~~
    322                 str:
        ~~~~~~~~~~~~~~~~~~~~
    ... 
    327                 encoding?: BufferEncoding,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    328             ): Buffer;
        ~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.

issue when I try to import anything from aws-iot-device-sdk-v2/lib/greengrasscoreipc/client like import * as greengrasscoreipc from 'aws-iot-device-sdk-v2/lib/greengrasscoreipc/client';, while importing aws-iot-device-sdk-v2/lib/greengrasscoreipc/model works fine.

I am using Node 18 and "typescript": "^5.0.4", my package.json is as following:

{
  "name": "@amzn/evergreen-assertion-node-js-component",
  "version": "0.1.0",
  "description": "",
  "author": "",
  "license": "UNLICENSED",
  "repository": "ssh://git.amazon.com/pkg/EvergreenAssertionNodeJSComponent",
  "homepage": "https://code.amazon.com/packages/EvergreenAssertionNodeJSComponent",
  "scripts": {
    "clean": "rm -rf dist && rm -rf node_modules",
    "build": "tsc",
    "watch": "tsc -w",
    "prepare": "npm run-script build",
    "prepublishOnly": "npm run build && npm run test",
    "test": "jest --collectCoverage --collectCoverageFrom=src/**/*.{ts,js}",
    "posttest": "generate-coverage-data --language typescript"
  },
  "jest": {
    "testMatch": [
      "**/**.test.ts"
    ],
    "transform": {
      ".(js|ts)": "ts-jest"
    },
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx|json)$",
      "package.json"
    ],
    "coverageReporters": [
      "cobertura"
    ]
  },
  "files": [],
  "npm-pretty-much": {
    "runTest": "never"
  },
  "devDependencies": {
    "@amzn/brazil": "^2.0.4",
    "@types/jest": "^28.1.1",
    "aws-iot-device-sdk-v2": "^1.12.1",
    "jest": "^29.3.1",
    "ts-jest": "^29.0.3",
    "typescript": "^5.0.4",
    "winston": "^3.3.3"
  }
}

Expected Behavior

Importing should work smoothly

Current Behavior

I can't import anything

Reproduction Steps

If you use Node18 and my package.json, you can probably hit this issue.

Possible Solution

No response

Additional Information/Context

No response

SDK version used

"aws-iot-device-sdk-v2": "^1.12.1",

Environment details (OS name and version, etc.)

MACOS

Xuqing888 commented 1 year ago

Looks like if I use:

        var greengrasscoreipc = require('aws-iot-device-sdk-v2/lib/greengrasscoreipc')
        const ipcClient = greengrasscoreipc.createClient()
        ipcClient.connect().then((r: any) => console.log(r));

then it works, but import {createClient} from 'aws-iot-device-sdk-v2/lib/greengrasscoreipc' doesn't work.

bretambrose commented 1 year ago

While the chance that it is our problem is pretty high vs. it being typescript's, I'm looking at https://nodejs.org/api/buffer.html#static-method-bufferfromarraybuffer-byteoffset-length and see nothing that indicates our usage is incorrect. You should be able to work around the issue by changing your version of typescript at the very least.

Xuqing888 commented 1 year ago

Thanks, what typescript version do you suggest here?

The reason I am using 5.0.x typescript if to work around another

node_modules/aws-iot-device-sdk-v2/lib/eventstream_rpc.ts:803:5 - error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.

803     constructor(private operationConfig: OperationConfig, private serviceModel: EventstreamRpcServiceModel) {
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
804         if (!serviceModel.operations.has(operationConfig.name)) {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
810         this.operation = new OperationBase(this.operationConfig);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
811     }
    ~~~~~

node_modules/aws-iot-device-sdk-v2/lib/eventstream_rpc.ts:888:5 - error TS2376: A 'super' call must be the first statement in the constructor when a class contains initialized properties, parameter properties, or private identifiers.

888     constructor(private request: RequestType, private operationConfig: OperationConfig, private serviceModel: EventstreamRpcServiceModel) {
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
889         if (!serviceModel.operations.has(operationConfig.name)) {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
900         this.responseHandled = false;
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
901     }
    ~~~~~

compilation error if I use ~4.x.x version. If I use 5.0.x version, this error is gone

bretambrose commented 1 year ago

I havent seen any issues with the version used by the gg_ipc sample.

bretambrose commented 1 year ago

I am able to build the gg_ipc sample with 5.0.4

Maybe you need to add @types/node to your project?

github-actions[bot] commented 1 year ago

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.