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

Type 'DynamoDBClient' does not satisfy the constraint 'SmithyClient'. #1803

Closed
jamesjrg opened this issue Dec 17, 2020 · 6 comments · Fixed by #1812
Closed

Type 'DynamoDBClient' does not satisfy the constraint 'SmithyClient'. #1803

jamesjrg opened this issue Dec 17, 2020 · 6 comments · Fixed by #1812
Assignees
Labels
bug This issue is a bug.

Comments

@jamesjrg
Copy link

jamesjrg commented Dec 17, 2020

Describe the bug
I'm not using the waiters code, but running "tsc" on a project using @aws-sdk/client-dynamodb throws this error:

yarn run v1.22.4
$ tsc
node_modules/@aws-sdk/client-dynamodb/types/waiters/waitForTableExists.d.ts:9:71 - error TS2344: Type 'DynamoDBClient' does not satisfy the constraint 'SmithyClient'.
  The types of 'middlewareStack.concat' are incompatible between these types.
    Type '<InputType extends ServiceInputTypes, OutputType extends ServiceOutputTypes>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<InputType, OutputType>' 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, ServiceOutputTypes>'.
          Types of property 'addRelativeTo' are incompatible.
            Type '(middleware: MiddlewareType<InputType, OutputType>, options: RelativeMiddlewareOptions) => void' is not assignable to type '(middleware: MiddlewareType<InputType, ServiceOutputTypes>, options: RelativeMiddlewareOptions) => void'.
              Types of parameters 'middleware' and 'middleware' are incompatible.
                Type 'MiddlewareType<InputType, ServiceOutputTypes>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                  Type 'InitializeMiddleware<InputType, ServiceOutputTypes>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                    Type 'InitializeMiddleware<InputType, ServiceOutputTypes>' is not assignable to type 'InitializeMiddleware<InputType, OutputType>'.
                      Call signature return types 'InitializeHandler<InputType, ServiceOutputTypes>' and 'InitializeHandler<InputType, OutputType>' are incompatible.
                        Type 'Promise<InitializeHandlerOutput<ServiceOutputTypes>>' is not assignable to type 'Promise<InitializeHandlerOutput<OutputType>>'.
                          Type 'InitializeHandlerOutput<ServiceOutputTypes>' is not assignable to type 'InitializeHandlerOutput<OutputType>'.
                            Types of property 'output' are incompatible.
                              Type 'ServiceOutputTypes' is not assignable to type 'OutputType'.
                                'ServiceOutputTypes' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'any'.
                                  Type 'MetadataBearer' is not assignable to type 'OutputType'.
                                    'MetadataBearer' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'any'.

Maybe the SDK doesn't work with older versions of typescript or something.

SDK version number

3.0.0

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version
Paste output of npx envinfo --browsers or node -v or react-native -v

node is v12.18.2

But maybe more useful is that typescript is 3.8.3

To Reproduce (observed behavior)
Given I haven't used the waiters code I wonder if just the include would cause it to fail, but this is approximately my code:

import { DynamoDB, GetItemCommand } from '@aws-sdk/client-dynamodb';
import { marshall, unmarshall } from '@aws-sdk/util-dynamodb';

const client = new DynamoDB({ region: 'eu-west-1' });
const command = new GetItemCommand({
    TableName: 'foo',
    Key: marshall({ myKey: "hello" }),
  });
  const { Item } = await client.send(command)
}

Expected behavior
It compiles.

@AllanZhengYP AllanZhengYP added the investigating Issue is being investigated and/or work is in progress to resolve the issue. label Dec 17, 2020
@AllanZhengYP AllanZhengYP self-assigned this Dec 17, 2020
@AllanZhengYP
Copy link
Contributor

AllanZhengYP commented Dec 17, 2020

@jamesjrg JS SDK v3 uses TS 4.1.2 for building the project, there COULD be some issues with TS 3.8. Normally, for TS project, you need to remove node_modules in the tsconfig.json, like this example.

Please let me know if you are still seeing the same error after excluding the node_modules.

UPDATE: I can reproduce with TS4.1.2

@AllanZhengYP AllanZhengYP added guidance General information and guidance, answers to FAQs, or recommended best practices/resources. response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed investigating Issue is being investigated and/or work is in progress to resolve the issue. labels Dec 17, 2020
@jamesjrg
Copy link
Author

This is the tsconfig.json currently being used, it appears to already exclude node_modules:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "sourceMap": true,
    "strict": true,
    "target": "es2019",
    "outDir": "./dist",
    "esModuleInterop": true
  },
  "include": ["./src/**/*.ts", "./types/**/*.ts"],
  "exclude": ["node_modules"]
}

I tried removing "strict": true, from the above config and that seems to make the compilation work, though not sure if that's a good idea. Possibly I need to use the v2 version of the SDK to use strict mode?

@AllanZhengYP AllanZhengYP added investigating Issue is being investigated and/or work is in progress to resolve the issue. and removed response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. labels Dec 17, 2020
@winjer
Copy link

winjer commented Dec 18, 2020

I am getting the same error with client-cloudformation with Typescript 4.1.3 and @types/node 14.14.14.

Can confirm removing "strict": true, resolves it.

I've tried various combinations of typescript and node types and hit this problem with all of them.

I can get the error with just this code:

import { CloudFormationClientConfig } from '@aws-sdk/client-cloudformation';

@96erardo
Copy link

I am getting a similar error that saids:

Type 'S3Client' does not satisfy the constraint 'SmithyClient'

@AllanZhengYP AllanZhengYP added bug This issue is a bug. and removed investigating Issue is being investigated and/or work is in progress to resolve the issue. labels Dec 18, 2020
@pwagener
Copy link

A less-scary work-around here would be to only disable two of the strict checks that tsc uses, allowing the rest of the strict checks to continue. The tsc options documentation notes that "strict": true actually enables the following more granular flags:

  • noImplicitAny,
  • noImplicitThis
  • alwaysStrict,
  • strictBindCallApply,
  • strictNullChecks
  • strictFunctionTypes
  • strictPropertyInitialization

This bug can be avoided by disabling strictNullChecks setting. The strictPropertyInitialization check is dependent on strictNullChecks though, so it must also be disabled. So, the following can be used to enable the rest of the strict checks while we wait for #1812 to be released:

...
    "noImplicitAny": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "strictNullChecks": false,
    "strictPropertyInitialization": false,
...

@AllanZhengYP AllanZhengYP removed the guidance General information and guidance, answers to FAQs, or recommended best practices/resources. label Dec 21, 2020
AllanZhengYP added a commit to AllanZhengYP/aws-sdk-js-v3 that referenced this issue Dec 23, 2020
Remove the type guard to unblock aws#1803.
TODO: add type guard that doesn't block the compile
AllanZhengYP added a commit that referenced this issue Dec 23, 2020
* fix(util-waiter): fix compiling error with waiter

* fix(util-waiter): remove type guard for client

Remove the type guard to unblock #1803.
TODO: add type guard that doesn't block the compile
@github-actions
Copy link

github-actions bot commented Jan 8, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants