dynamodb-toolbox
dynamodb-toolbox copied to clipboard
Type inference issue when using pnpm
Hi, I'm currently utilizing pnpm for my project and I've come across a TypeScript issue:
"The inferred type of 'putUserTest' cannot be named without a reference to '.pnpm/[email protected]/node_modules/ts-toolbelt/out/Object/Omit'. This is likely not portable. A type annotation is necessary.ts(2742)"
async putUserTest(username: string) {
return UserEntity.put({ userId: username });
}
This fix the issue, but now I'm no longer receiving type suggestions
async putUserTest(username: string) {
return (UserEntity as any).put({ userId: username });
}
Hey, thanks for creating this issue. Mind sharing a bit more context so I could try to reproduce this? (PNPM version, OS, etc.)
Thanks!
pnpm: v8.2.0 dynamodb-toolbox: v0.8.5 typescript: v4.9.5 OS: Linux (Fedora)
I think it's a common pnpm problem.
Hey @AlexRequelme, sorry for the delayed response.
I managed to re-create this issue but not sure what's the best approach for this atm, this thread, seems to discuss this exact topic.
I believe this is a duplicate of #631. If interested there is a link to https://github.com/microsoft/TypeScript/issues/47663 in the duplicate issue which states the root cause which is a TypeScript issue and not an issue with this repo. One thing I have found that fixes this:
If you check your tsconfig.json
and the moduleResolution
is set to bundler
or nodenext
and not node
then this will break. Please try setting "moduleResolution": "node"
as this has fixed the issue for me.
In a huge monorepo where project shared TS config changing is not an option, unfortunately, and some core packages force to set it to Bundler
. As you know, this is a new TS way, and when the decision was made to upgrade to 5. x this was one of the changes. No other package has issues, so the team will probably be forced to put the usage of the DynamoDB Toolbox on hold.
I believe this is a duplicate of #631. If interested there is a link to microsoft/TypeScript#47663 in the duplicate issue which states the root cause which is a TypeScript issue and not an issue with this repo. One thing I have found that fixes this:
If you check your
tsconfig.json
and themoduleResolution
is set tobundler
ornodenext
and notnode
then this will break. Please try setting"moduleResolution": "node"
as this has fixed the issue for me.
Thank you this was the solution i needed to deal with the same issue on a monorepo using PNPM!