Skip to content

Commit

Permalink
fix: broken ChecksumConfiguration and ConditionalRecursiveTransformEx…
Browse files Browse the repository at this point in the history
…act interface in TS < 4.4 (#926)

* fix: broken ChecksumConfiguration interface in TS < 4.4

Before TS 4.4, TS does not allow the index signature as union type. Consuming library with this interface will cause error:
"TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
[other: string | number]: any;". This issue was fixed in TS 4.4: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#symbol-and-template-string-pattern-index-signatures

Fixing this issue so it won't break users with TSC < 4.4

* fix(types): conditional generic types in TS<4.1

The referred type `ConditionalRecursiveTransformExact<T, FromType, ToType>` uses
conditional generic type that is only supported in TS>=4.1. However the typesVersions
directs consumers' TSC 4.0 to the types with this definition, hence consumers will see
following error:

error TS2315: Type 'ConditionalRecursiveTransformExact' is not generic.

Changing the typesVersions directive resolves the issue.
  • Loading branch information
AllanZhengYP authored Sep 12, 2023
1 parent 2d9473c commit b926581
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-kids-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/types": patch
---

fix: broken ChecksumConfiguration interface in TS < 4.4 and conditional generic types in TS<4.1
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"node": ">=14.0.0"
},
"typesVersions": {
"<4.0": {
"<=4.0": {
"dist-types/*": [
"dist-types/ts3.4/*"
]
Expand Down
17 changes: 11 additions & 6 deletions packages/types/src/extensions/checksum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@ export interface ChecksumAlgorithm {
}

/**
* @internal
* @deprecated unused.
*/
export interface ChecksumConfiguration {
addChecksumAlgorithm(algo: ChecksumAlgorithm): void;
checksumAlgorithms(): ChecksumAlgorithm[];

type ChecksumConfigurationLegacy = {
/**
* @deprecated unused.
*/
[other: string | number]: any;
[other in string | number]: any;
};

/**
* @internal
*/
export interface ChecksumConfiguration extends ChecksumConfigurationLegacy {
addChecksumAlgorithm(algo: ChecksumAlgorithm): void;
checksumAlgorithms(): ChecksumAlgorithm[];
}

/**
Expand Down

0 comments on commit b926581

Please sign in to comment.