Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(util-dynamodb): narrow NativeAttributeValue to remove implicit any (#7526)#7989

Open
mohanrajvenkatesan23-04 wants to merge 1 commit into
aws:mainfrom
mohanrajvenkatesan23-04:fix/issue-7526-native-attribute-value-any
Open

fix(util-dynamodb): narrow NativeAttributeValue to remove implicit any (#7526)#7989
mohanrajvenkatesan23-04 wants to merge 1 commit into
aws:mainfrom
mohanrajvenkatesan23-04:fix/issue-7526-native-attribute-value-any

Conversation

@mohanrajvenkatesan23-04
Copy link
Copy Markdown

Issue

Fixes #7526NativeAttributeValue type resolves to any.

Description

The NativeAttributeValue union exported from @aws-sdk/util-dynamodb (and re-exported by @aws-sdk/lib-dynamodb) included InstanceType<{ new (...args: any[]): any }> as a union member. TypeScript widens InstanceType<{ new (...args: any[]): any }> to any, which collapsed the entire union to any and silently disabled type-checking for every consumer of the DynamoDB Document Client (PutCommand, UpdateCommand, marshall, convertToAttr, etc.).

The maintainer (@kuhe) identified the fix in a comment on the issue: remove that member from the union. This PR removes it and resolves the latent typecheck errors that surfaced inside the package once the implicit any was no longer absorbing them — three small internal cast adjustments in convertToAttr.ts, marshall.ts, and unmarshall.ts. No runtime behavior changes.

Files changed:

  • packages-internal/util-dynamodb/src/models.ts — the actual type fix (drop the InstanceType<...> union member that widened to any).
  • packages-internal/util-dynamodb/src/convertToAttr.ts — small local-cast adjustment to satisfy the now-stricter union.
  • packages-internal/util-dynamodb/src/marshall.ts — small cast adjustment.
  • packages-internal/util-dynamodb/src/unmarshall.ts — small cast adjustment.
  • packages-internal/util-dynamodb/src/NativeAttributeValue.spec.ts — new regression spec.

Note on breaking-ness: This is a type-only change. Runtime behavior is identical. Downstream users currently passing arbitrary class instances directly into marshall/convertToAttr (relying on convertClassInstanceToMap) will now see compile errors at the call site. The maintainer flagged the original bug as "breaking"; this PR follows their guidance.

generated by AI tools, and reviewed by Mohanraj Venkatesan

Testing

Added packages-internal/util-dynamodb/src/NativeAttributeValue.spec.ts with 16 Vitest cases:

  • 13 positive assignments covering every supported native type (string, number, boolean, null, undefined, bigint, NumberValue, Uint8Array, ArrayBuffer, Set variants, map, list).
  • 3 // @ts-expect-error regressions that verify the union no longer collapses to any (function, symbol, and a parameter-not-narrowed case).

Verified the regression tests catch the original bug: temporarily restoring the offending union member produces 3 TS2578: Unused '@ts-expect-error' directive errors, exactly as expected.

Local results:

  • npx vitest run in packages-internal/util-dynamodb388/388 pass (372 pre-existing + 16 new).
  • npx tsc --noEmit -p tsconfig.types.json — only pre-existing baseline errors remain (4 @aws-sdk/client-dynamodb module-resolution errors due to missing local dist-*/ outputs, plus one pre-existing unused-directive). No new errors introduced.

Checklist

  • Linked to the original issue (NativeAttributeValue type is any #7526).
  • Added a regression test that fails on main and passes with this fix.
  • All existing tests in the affected package still pass (vitest run: 388/388).
  • No new tsc --noEmit errors introduced.
  • Husky pre-commit hooks pass (lint-staged, lint:versions, lint:dependencies, lint:api).
  • AI disclosure included in Description per repo policy.

aws#7526)

The NativeAttributeValue union included InstanceType<{ new (...args: any[]): any }>,
which TypeScript widens to any and caused the entire union to collapse to any,
silently disabling type-checking for every consumer of the DynamoDB Document Client.

Remove that union member and adjust three internal casts in convertToAttr.ts,
marshall.ts, and unmarshall.ts that surfaced once the implicit any was no longer
absorbing them. Type-only change; runtime behavior is unchanged.

Adds packages-internal/util-dynamodb/src/NativeAttributeValue.spec.ts with
positive assignments for all supported native types and @ts-expect-error
regressions to guard against the union collapsing to any again.
@mohanrajvenkatesan23-04 mohanrajvenkatesan23-04 requested a review from a team as a code owner May 6, 2026 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NativeAttributeValue type is any

1 participant