Skip to content

Commit 77ac0f5

Browse files
Harmeet SinghHarmeet Singh
authored andcommitted
fix the typescript compile issue 2
1 parent 98fc7ee commit 77ac0f5

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

ng-package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@
1010
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
1111
"dest": "dist",
1212
"lib": { "entryFile": "src/index.ts" },
13-
"tsconfig": "tsconfig.lib.json"
1413
}
1514

src/lib/datagrid/datagrid.component.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,22 @@ export class Datagrid<T = any> implements AfterContentInit, OnChanges {
285285
public filterTpls: Record<string, NgbFilterTemplate<T>> = {};
286286
public globalTpl: NgbGlobalFilterTemplate | null = null;
287287

288+
private toRecord<T extends { field: string }>(
289+
items: readonly T[] | QueryList<T> | null | undefined
290+
): Record<string, T> {
291+
const arr = Array.isArray(items)
292+
? items
293+
: items instanceof QueryList
294+
? items.toArray()
295+
: [];
296+
return arr.reduce((acc, t) => (acc[t.field] = t, acc), {} as Record<string, T>);
297+
}
298+
288299
ngAfterContentInit(): void {
289300
const rebuild = () => {
290-
this.cellTpls = Object.fromEntries(this.cellTplQ?.map(t => [t.field, t]) ?? []);
291-
this.editTpls = Object.fromEntries(this.editTplQ?.map(t => [t.field, t]) ?? []);
292-
this.filterTpls = Object.fromEntries(this.filterTplQ?.map(t => [t.field, t]) ?? []);
301+
this.cellTpls = this.toRecord(this.cellTplQ);
302+
this.editTpls = this.toRecord(this.editTplQ);
303+
this.filterTpls = this.toRecord(this.filterTplQ);
293304
this.globalTpl = this.globalTplQ?.first ?? null;
294305
};
295306
rebuild();

tsconfig.lib.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"declaration": true,
66
"declarationMap": true,
77
"inlineSources": true,
8-
"types": [],
9-
"target": "ES2020",
10-
"lib": ["ES2020", "DOM"]
8+
"types": []
119
},
1210
"exclude": [
1311
"src/**/*.spec.ts",

tsconfig.lib.prod.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"extends": "./tsconfig.lib.json",
33
"compilerOptions": {
4-
"declarationMap": false,
5-
"target": "ES2020",
6-
"lib": ["ES2020", "DOM"]
4+
"declarationMap": false
75
},
86
"angularCompilerOptions": {
97
"compilationMode": "partial"

0 commit comments

Comments
 (0)