Skip to content

Commit a06f070

Browse files
committed
better typescript lib
1 parent 772a5b2 commit a06f070

File tree

4 files changed

+214
-4
lines changed

4 files changed

+214
-4
lines changed

lib/src/lib/databases/localstorage-database.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,23 @@ export class LocalStorageDatabase implements LocalDatabase {
7070
* @param data The item's value
7171
* @returns A RxJS `Observable` to wait the end of the operation
7272
*/
73-
set(key: string, data: unknown): Observable<undefined> {
73+
set(key: string, data: object): Observable<undefined> {
7474

75-
let serializedData: string | null = null;
75+
let serializedData: StringifyResult<object> | null = null;
7676

7777
/* Check if data can be serialized */
78-
const dataPrototype: unknown = Object.getPrototypeOf(data);
79-
if ((typeof data === "object") && (data !== null) && !Array.isArray(data) &&
78+
const dataPrototype = Object.getPrototypeOf(data);
79+
if ((typeof data === "object") && !Array.isArray(data) &&
8080
!((dataPrototype === Object.prototype) || (dataPrototype === null))) {
8181
return throwError(() => new SerializationError());
8282
}
8383

8484
/* Try to stringify (can fail on circular references) */
8585
try {
8686
serializedData = JSON.stringify(data);
87+
if (serializedData === undefined) {
88+
throw new Error();
89+
}
8790
} catch (error) {
8891
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
8992
return throwError(() => error as TypeError);

lib/src/lib/validation/json-validator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export class JSONValidator {
194194
if (Array.isArray(schema.items) || schema.items === undefined) {
195195

196196
// TODO: cast should not be needed here
197+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
197198
return this.validateTuple(data, schema.items as JSONSchema[] | undefined);
198199

199200
}

package-lock.json

Lines changed: 205 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@sinclair/typebox": "^0.34.4",
4646
"@types/jasmine": "~5.1.1",
4747
"angular-eslint": "^18.4.1",
48+
"better-typescript-lib": "~2.9.0",
4849
"copyfiles": "^2.4.1",
4950
"eslint": "^9.15.0",
5051
"jasmine-core": "~5.4.0",

0 commit comments

Comments
 (0)