aws-lite
aws-lite copied to clipboard
Bug with TS & DynamoDB plugin with TS option `strict` is enabled
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__dynamodbif it exists or add a new declaration (.d.ts) file containingdeclare 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 https://github.com/architect/aws-lite/issues/70 but maybe without the same option in tsconfig file.
Expected behavior
It compiles without error.
Steps to reproduce
- Install both the client & dynamo plugin
- Enable TS config with option
strictornoImplicitAnyset totrue - Setup awsLite to use the Dynamo plugin
- 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
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
Hey @tbeseda,
Did you install the
@aws-lite/dynamodb-typespackage? 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.
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.
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",
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:
- up to the consumer, you drop a d.ts file with the above somewhere that TS will pick it up.
- in the
@aws-lite/ssmpackage; add a types field in package.json and point it at that one-liner. - in the
@aws-lite/ssm-typespackage; drop that line inindex.d.tssomewhere.
It's worth noting that AwsLiteConfig['plugins'] is any[].
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.
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!
Any update on this. Just looking at trying aws-lite for dynamodb usage and encountered this exact issue.
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'
}