Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command assignable type issue #1277

Open
jsapes opened this issue May 13, 2024 · 2 comments
Open

Command assignable type issue #1277

jsapes opened this issue May 13, 2024 · 2 comments
Labels
response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days.

Comments

@jsapes
Copy link

jsapes commented May 13, 2024

Hi! We were using Command and it was working with version 2.x.x and right now after updating to version 3.0.0. Is failing. I've tried to understand why, but I don't understand what happen. Can you explain me what I have to change to migrate to the newest version?

We have a generic class that uses Command from your package


export class DynamoQueryBuilderCommand<T extends Command<any, any, any, any, any>> {
  private readonly commandFactory: CommandFactory<T>;

  constructor(commandFactory: CommandFactory<T>) {
    this.commandFactory = once(commandFactory); // once is 
  }
  ....
}

export type CommandFactory<T extends Command<any, any, any, any, any>> = () => T | Promise<T>;

function once<T extends (...args: any[]) => any>(fn: T): T {
  let called = false;
  let result: ReturnType<T> | undefined;

  return function (this: any, ...args: Parameters<T>): ReturnType<T> {
    if (!called) {
      called = true;
      result = fn.apply(this, args);
    }

    return result as ReturnType<T>;
  } as T;
}

We are calling it from different classes.

import {  GetCommand } from '@aws-sdk/lib-dynamodb';

export class DynamoQueryBuilder {
 // constructor and other methods 

 findOneById(id: string): DynamoQueryBuilderCommand<GetCommand> { // This was working and right now it fails
    const command: GetCommandInput = {
      TableName: this.tableName,
      Key: id),
    };

    return new DynamoQueryBuilderCommand(() => new GetCommand(command));
  }

}

We are having the following issue:

Dynamo-query-builder.ts:- error TS2344: Type 'GetCommand' does not satisfy the constraint 'Command<any, any, any, any, any>'.
  The types of 'middlewareStack.concat' are incompatible between these types.
    Type '<InputType extends GetItemCommandInput | GetCommandInput, OutputType extends GetItemCommandOutput | GetCommandOutput>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<...>' is not assignable to type '<InputType extends any, OutputType extends any>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<InputType, OutputType>'.
      Types of parameters 'from' and 'from' are incompatible.
        Type 'MiddlewareStack<InputType, OutputType>' is not assignable to type 'MiddlewareStack<InputType, GetItemCommandOutput | GetCommandOutput>'.
          Types of property 'addRelativeTo' are incompatible.
            Type '(middleware: MiddlewareType<InputType, OutputType>, options: RelativeMiddlewareOptions) => void' is not assignable to type '(middleware: MiddlewareType<InputType, GetItemCommandOutput | GetCommandOutput>, options: RelativeMiddlewareOptions) => void'.
              Types of parameters 'middleware' and 'middleware' are incompatible.
                Type 'MiddlewareType<InputType, GetItemCommandOutput | GetCommandOutput>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                  Type 'InitializeMiddleware<InputType, GetItemCommandOutput | GetCommandOutput>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                    Type 'InitializeMiddleware<InputType, GetItemCommandOutput | GetCommandOutput>' is not assignable to type 'InitializeMiddleware<InputType, OutputType>'.
                      Call signature return types 'InitializeHandler<InputType, GetItemCommandOutput | GetCommandOutput>' and 'InitializeHandler<InputType, OutputType>' are incompatible.
                        Type 'Promise<InitializeHandlerOutput<GetItemCommandOutput | GetCommandOutput>>' is not assignable to type 'Promise<InitializeHandlerOutput<OutputType>>'.
                          Type 'InitializeHandlerOutput<GetItemCommandOutput | GetCommandOutput>' is not assignable to type 'InitializeHandlerOutput<OutputType>'.
                            Types of property 'output' are incompatible.
                              Type 'GetItemCommandOutput | GetCommandOutput' is not assignable to type 'OutputType'.
                                'GetItemCommandOutput | GetCommandOutput' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'any'.
                                  Type 'GetItemCommandOutput' is not assignable to type 'OutputType'.
                                    'GetItemCommandOutput' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'any'.

44   findOneById(id: StrictUnion<PrimaryKey>): DynamoQueryBuilderCommand<GetCommand> {
                                                                         ~~~~~~~~~~

src/dynamo/dynamo-query-builder.ts:50:5 - error TS2322: Type 'DynamoQueryBuilderCommand<Command<any, any, any, any, any>>' is not assignable to type 'DynamoQueryBuilderCommand<GetCommand>'.
  Type 'Command<any, any, any, any, any>' is missing the following properties from type 'GetCommand': inputKeyNodes, outputKeyNodes, clientCommand, addMarshallingMiddleware, resolveMiddlewareWithContext

50     return new DynamoQueryBuilderCommand(() => new GetCommand(command));
       ~~~~~~

Reading the docs I see the new version is for node16 support, so I don't understand whats going on. Any idea how to solve this issue? It is really wanted? Many thanks!

@danewilson
Copy link

For us this was caused by multiple versions of the @smithy/types package. Make sure you're using v3 everywhere, including in deps of deps where possible (you may have to upgrade other AWS deps).

@syall
Copy link
Contributor

syall commented May 13, 2024

@jsapes, like @danewilson mentioned this is probably due to inconsistent usage of dependencies (we released a major version bump to support Node 16 as a minimum version from Node 14).

Could you try updating the dependencies to the latest version and seeing if that works?

@syall syall added the response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days.
Projects
None yet
Development

No branches or pull requests

3 participants