dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Type inference issue when using pnpm

Open alexrequelme opened this issue 1 year ago • 5 comments

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 });
}

alexrequelme avatar Jul 10 '23 02:07 alexrequelme

Hey, thanks for creating this issue. Mind sharing a bit more context so I could try to reproduce this? (PNPM version, OS, etc.)

Thanks!

naorpeled avatar Jul 10 '23 21:07 naorpeled

pnpm: v8.2.0 dynamodb-toolbox: v0.8.5 typescript: v4.9.5 OS: Linux (Fedora)

I think it's a common pnpm problem.

alexrequelme avatar Jul 11 '23 00:07 alexrequelme

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.

naorpeled avatar Jul 25 '23 08:07 naorpeled

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.

SpencerDuball avatar Dec 10 '23 23:12 SpencerDuball

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.

rdzidziguri avatar Dec 16 '23 21:12 rdzidziguri

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 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.

Thank you this was the solution i needed to deal with the same issue on a monorepo using PNPM!

liamlows avatar Mar 13 '24 19:03 liamlows