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

Bug with TS & DynamoDB plugin with TS option strict is enabled #100

Open
j0k3r opened this issue Feb 8, 2024 · 9 comments
Open

Bug with TS & DynamoDB plugin with TS option strict is enabled #100

j0k3r opened this issue Feb 8, 2024 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@j0k3r
Copy link

j0k3r commented Feb 8, 2024

Describe the issue

When using the plugin with TS, I got the error:

error TS7016: Could not find a declaration file for module '@aws-lite/dynamodb'. '/..../node_modules/@aws-lite/dynamodb/src/index.mjs' implicitly has an 'any' type.
Try npm i --save-dev @types/aws-lite__dynamodb if it exists or add a new declaration (.d.ts) file containing declare module '@aws-lite/dynamodb';

2 import dynamodb from '@aws-lite/dynamodb'

I've properly updated my tsconfig.json.
The bug appear because I've these options defined in the config file:

 "strict": true,
 "noImplicitAny": true,

Enable at least one of those option, raise the above error when running yarn tsc.

Might be the same as #70 but maybe without the same option in tsconfig file.

Expected behavior

It compiles without error.

Steps to reproduce

  1. Install both the client & dynamo plugin
  2. Enable TS config with option strict or noImplicitAny set to true
  3. Setup awsLite to use the Dynamo plugin
  4. Launch yarn tsc

Platform / version

  • OS + version: (e.g. iOS 17.2) unimportant
  • Node version: (e.g. Node.js 20.5) v20.10.0
  • Package manager version: (e.g. npm 10.2) 1.22.21
  • Browser: (e.g. Chrome 70.5, if applicable) unimportant
  • TS 4

How urgent do you feel this bug is?

P2

Additional context

No response

@j0k3r j0k3r added the bug Something isn't working label Feb 8, 2024
@j0k3r j0k3r changed the title But with TS & DynamoDB plugin Bug with TS & DynamoDB plugin with TS option strict is enabled Feb 8, 2024
@tbeseda
Copy link
Contributor

tbeseda commented Feb 8, 2024

Hi @j0k3r thanks for steps to repro.
Did you install the @aws-lite/dynamodb-types package? it provides "ambient" types for the .DynamoDB interface.

I think you might have because you mentioned that it's similar to #70 and that resolution was this in the tsconfig

{
  "compilerOptions": {
    "types": [
      "@aws-lite/dynamodb-types"
    ]
  }
}

But I just want to double check.

Also, a new version of aws-lite went out very recently that requires explicit loading of plugins. Are you using @aws-lite/[email protected]?

That'll help me differentiate pre-0.17 vs latest. Thanks

@j0k3r
Copy link
Author

j0k3r commented Feb 13, 2024

Hey @tbeseda,

Did you install the @aws-lite/dynamodb-types package? it provides "ambient" types for the .DynamoDB interface.

Yes, sorry I didn't mention it. We do have that package:

"@aws-lite/dynamodb-types": "^0.3.5",

that resolution was this in the tsconfig

Yes it's enabled.

{
  "compilerOptions": {
    "incremental": true,
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": true,
    "skipLibCheck": true,
    "noEmit": true,
    "types": [
      "@aws-lite/dynamodb-types",
      "@types/jest"
    ]
  },
  "include": [
    "src",
    "tests",
    "jest.config.ts",
    "webpack.config.js"
  ],
  "exclude": [
    "node_modules/**/*",
    ".serverless/**/*",
    ".webpack/**/*",
    ".vscode/**/*"
  ]
}

Are you using @aws-lite/[email protected]?

We are using the latest client:

"@aws-lite/client": "^0.17.2",

This is how we are creating the client:

import awsLite from '@aws-lite/client'
import dynamodb from '@aws-lite/dynamodb'

const awsLiteConfig = {
  region: 'eu-west-1',
  plugins: [dynamodb],
  autoloadPlugins: false,
}
const aws = await awsLite(awsLiteConfig)

Overall, the error is still here.

@tbeseda
Copy link
Contributor

tbeseda commented Feb 13, 2024

Thanks for getting back to me and adding more info. I'm working on an update to type defs today, so I can look into this with your configuration today.

@tbeseda tbeseda self-assigned this Feb 13, 2024
@imdkbj
Copy link

imdkbj commented Mar 24, 2024

hey @tbeseda I am facing same types issue.

Cannot find type definition file for '@aws-lite/sqs-types'.
The file is in the program because:
Entry point of type library '@aws-lite/sqs-types' specified in compilerOptionsts

Tried

    "typeRoots": ["node_modules/@types", "src/@types", "@aws-lite/sqs-types"],
    "types": ["@aws-lite/sqs-types"],
    "dependencies": {
    "@aws-lite/client": "^0.19.0",
    "@aws-lite/sqs": "^0.2.1",
    
   
    "devDependencies": {
    "@aws-lite/sqs-types": "^0.2.3",
    

@keithlayne
Copy link

Ran into this in my first foray into aws-lite. As an example, @aws-lite/[email protected] has this declaration:

declare module "@aws-lite/client" {
  interface AwsLiteClient {
    SSM: AwsLiteSSM;
  }
}

This is good, it merges SSM stuff into the client. The actual TS error is in the import statement (either import or import()) - there's no declaration for the actual @aws-lite/ssm module.

You can make this go away with:

declare module '@aws-lite/ssm';

It's not clear to me where this should happen - it can be:

  1. up to the consumer, you drop a d.ts file with the above somewhere that TS will pick it up.
  2. in the @aws-lite/ssm package; add a types field in package.json and point it at that one-liner.
  3. in the @aws-lite/ssm-types package; drop that line in index.d.ts somewhere.

It's worth noting that AwsLiteConfig['plugins'] is any[].

@tbeseda
Copy link
Contributor

tbeseda commented Apr 8, 2024

Thanks for the diagnostics here @keithlayne - very helpful. I'm taking a look at this today to see how much can be handled automatically by aws-lite and what we should advise consumers do.

@tbeseda
Copy link
Contributor

tbeseda commented Apr 15, 2024

Okay finally an update here:

I recreated the issue locally in a fresh TS project with the following config:

{
  "scripts": {
    "build": "tsc"
  },
  "devDependencies": {
    "@aws-lite/ssm-types": "^0.2.5",
    "@types/node": "^20.12.7",
    "typescript": "^5.4.5"
  },
  "dependencies": {
    "@aws-lite/client": "^0.20.0",
    "@aws-lite/ssm": "^0.2.3"
  }
}
{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "target": "ES6",
    "types": [
      "@aws-lite/ssm-types"
    ]
  }
}

my working index.ts:

import awsLite from '@aws-lite/client'
import awsLiteSsm from '@aws-lite/ssm'

(async () => {
  const aws = await awsLite({
    plugins: [awsLiteSsm]
  })

  await aws.SSM.GetParameter({
    Name: 'foobar',
    WithDecryption: true,
  })
})()

this required a couple updates to the base aws-lite/client types. namely:

/// <reference types="node" />
// ...
declare module "@aws-lite/client";
export default function awsLite(config: AwsLiteConfig): Promise<AwsLiteClient>;

further, I added a "types" field to aws-lite/ssm's package.json that points to a file that simply does:

declare module '@aws-lite/ssm';

I was not able to use that one-liner in the aws-lite/ssm-types. I get:

Invalid module name in augmentation.
Module '@aws-lite/ssm' resolves to an untyped module at '/node_modules/@aws-lite/ssm/src/index.mjs', 
which cannot be augmented

Ideally, I could get this working by only changing the types package and not adding a file to the plugin. Research continues. Suggestions welcome!

@agawley
Copy link

agawley commented Aug 16, 2024

Any update on this. Just looking at trying aws-lite for dynamodb usage and encountered this exact issue.

@dirkluijk
Copy link

dirkluijk commented Sep 19, 2024

Having the same issue here. I think there is a mistake somewhere, but I'm still unable to figure out what.

To see this issue in action: https://stackblitz.com/edit/stackblitz-starters-u8a5t1 (execute npm run build from the terminal)

The setup is also a bit unusual. My suggestion would be to publish the types in the https://github.com/DefinitelyTyped/DefinitelyTyped repo instead. Or start rewriting this SDK to TypeScript, so that the typings can be included in the same packages as the source code.

A workaround is to add a file, e.g. @aws-lite-dynamodb.d.ts, containing:

declare module '@aws-lite/dynamodb' {
    export * from '@aws-lite/dynamodb-types'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants