Skip to content

Commit 3f308fa

Browse files
authored
Merge pull request #1019 from cyrilletuzi:bettertslib
better typescript lib
2 parents 772a5b2 + cf572cb commit 3f308fa

File tree

7 files changed

+222
-7
lines changed

7 files changed

+222
-7
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Build the lib (with the current version, as it is what is published on npm)
5656
run: npm run build
5757
- name: Downgrade dependencies to minimal required version
58-
run: npm install [email protected] [email protected] [email protected] [email protected] @angular/common@next @angular/compiler@next @angular/core@next @angular/platform-browser@next @angular/router@next @angular/cli@next @angular/compiler-cli@next @angular-devkit/build-angular@next --legacy-peer-deps
58+
run: npm install [email protected] [email protected] [email protected] [email protected] @angular/common@19.0.0 @angular/compiler@19.0.0 @angular/core@19.0.0 @angular/platform-browser@19.0.0 @angular/router@19.0.0 @angular/cli@19.0.0 @angular/compiler-cli@19.0.0 @angular-devkit/build-angular@19.0.0 --legacy-peer-deps
5959
env:
6060
CI: true
6161
- name: Run unit tests

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",

testing-apps/demo/src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { bootstrapApplication } from "@angular/platform-browser";
22
import { AppComponent } from "./app/app.component";
33

44
bootstrapApplication(AppComponent)
5-
.catch((err) => {
5+
.then(() => {
6+
// Nothing to do
7+
}, (err) => {
68
console.error(err);
79
});

testing-apps/localforage/src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { HomeComponent } from "./app/home/home.component";
77
bootstrapApplication(AppComponent, {
88
providers: [
99
provideRouter([
10+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
1011
{ path: "lazy", loadChildren: () => import("./app/lazy/routes").then(m => m.routes) },
1112
{ path: "", component: HomeComponent, pathMatch: "full" },
1213
]),
@@ -15,6 +16,8 @@ bootstrapApplication(AppComponent, {
1516
provideIndexedDBStoreName("keyvaluepairs"),
1617
],
1718
})
18-
.catch((err) => {
19+
.then(() => {
20+
// Nothing to do
21+
}, (err) => {
1922
console.error(err);
2023
});

0 commit comments

Comments
 (0)