-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#IOPID-1450] Enable
strict
mode on repo (#231)
* [#IOPID-1450] enable noImplicitThis * [#IOPID-1450] enable alwaysStrict * [#IOPID-1450] enable strictBindCallApply * [#IOPID-1450] enable strictFunctionTypes * [#IOPID-1450] enable noImplicitAny and useUnknownInCatchVariables * [#IOPID-1450] enable strictNullChecks * [#IOPID-1450] enable strictPropertyInitialization * [#IOPID-1450] enable strict * Update DeleteUserDataActivity/utils.ts Co-authored-by: Rodolfo Viti <62432865+rodoviti@users.noreply.github.com> * [#IOPID-1450] add tests for isCosmosErrors * [#IOPID-1450] refactor based on comments, part 1 * [#IOPID-1450] refactor based on comments, part 2 --------- Co-authored-by: Rodolfo Viti <62432865+rodoviti@users.noreply.github.com>
- Loading branch information
Showing
51 changed files
with
461 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { CosmosErrors } from "@pagopa/io-functions-commons/dist/src/utils/cosmosdb_model"; | ||
|
||
import { isCosmosErrors } from "../utils"; | ||
|
||
describe("utils", () => { | ||
// -------------- | ||
// Just a bunch of types needed for creating a tuple from an union type | ||
// See https://www.hacklewayne.com/typescript-convert-union-to-tuple-array-yes-but-how | ||
type Contra<T> = T extends any ? (arg: T) => void : never; | ||
type InferContra<T> = [T] extends [(arg: infer I) => void] ? I : never; | ||
type PickOne<T> = InferContra<InferContra<Contra<Contra<T>>>>; | ||
type Union2Tuple<T> = PickOne<T> extends infer U // assign PickOne<T> to U | ||
? Exclude<T, U> extends never // T and U are the same | ||
? [T] | ||
: [...Union2Tuple<Exclude<T, U>>, U] // recursion | ||
: never; | ||
// -------------- | ||
|
||
type CosmosErrorsTypesTuple = Union2Tuple<CosmosErrors["kind"]>; | ||
|
||
// NOTE: If a new cosmos error is added, the following initialization will not compile, | ||
// forcing us to update `CosmosErrorsTypes` with the new value | ||
const values: CosmosErrorsTypesTuple = [ | ||
"COSMOS_EMPTY_RESPONSE", | ||
"COSMOS_CONFLICT_RESPONSE", | ||
"COSMOS_DECODING_ERROR", | ||
"COSMOS_ERROR_RESPONSE" | ||
]; | ||
|
||
it.each(values)( | ||
"isCosmosErrors should return true if error is a CosmosError of type %s", | ||
v => { | ||
expect(isCosmosErrors({ kind: v })).toBe(true); | ||
} | ||
); | ||
|
||
it("isCosmosErrors should return false if error is not a CosmosError", () => { | ||
expect(isCosmosErrors({ kind: "ANOTHER_ERROR" })).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.