Skip to content

Commit af04132

Browse files
committed
Fix: Add null guards and explicit return types
- Add null/undefined check in isQueryCustomType - Add explicit return types for resource methods - Add null guard in EDM parser converters
1 parent 67b702c commit af04132

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

projects/angular-odata/src/lib/resources/query/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export const binary = (value: string): QueryCustomType => ({
106106
value,
107107
});
108108
export const isQueryCustomType = (value: any) =>
109-
typeof value === 'object' && 'type' in value && value.type in QueryCustomTypes;
109+
value !== null && value !== undefined && typeof value === 'object' && 'type' in value && value.type in QueryCustomTypes;
110110

111111
export const isRawType = (value: any) =>
112112
isQueryCustomType(value) && (value as QueryCustomType).type === QueryCustomTypes.Raw;

projects/angular-odata/src/lib/resources/types/entity.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ export class ODataEntityResource<T> extends ODataResource<T> {
5858
});
5959
}
6060

61-
navigationProperty<N>(path: string) {
61+
navigationProperty<N>(path: string): ODataNavigationPropertyResource<N> {
6262
return ODataNavigationPropertyResource.fromResource<N>(this, path);
6363
}
6464

65-
property<P>(path: string) {
65+
property<P>(path: string): ODataPropertyResource<P> {
6666
return ODataPropertyResource.fromResource<P>(this, path);
6767
}
6868

69-
action<P, R>(path: string) {
69+
action<P, R>(path: string): ODataActionResource<P, R> {
7070
return ODataActionResource.fromResource<P, R>(this, path);
7171
}
7272

73-
function<P, R>(path: string) {
73+
function<P, R>(path: string): ODataFunctionResource<P, R> {
7474
return ODataFunctionResource.fromResource<P, R>(this, path);
7575
}
7676

projects/angular-odata/src/lib/resources/types/navigation-property.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ export class ODataNavigationPropertyResource<T> extends ODataResource<T> {
122122
});
123123
}
124124

125-
navigationProperty<N>(path: string) {
125+
navigationProperty<N>(path: string): ODataNavigationPropertyResource<N> {
126126
return ODataNavigationPropertyResource.fromResource<N>(this, path);
127127
}
128128

129-
property<P>(path: string) {
129+
property<P>(path: string): ODataPropertyResource<P> {
130130
return ODataPropertyResource.fromResource<P>(this, path);
131131
}
132132

projects/angular-odata/src/lib/resources/types/singleton.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ export class ODataSingletonResource<T> extends ODataResource<T> {
5454
return singleton;
5555
}
5656

57-
navigationProperty<N>(path: string) {
57+
navigationProperty<N>(path: string): ODataNavigationPropertyResource<N> {
5858
return ODataNavigationPropertyResource.fromResource<N>(this, path);
5959
}
6060

61-
property<P>(path: string) {
61+
property<P>(path: string): ODataPropertyResource<P> {
6262
return ODataPropertyResource.fromResource<P>(this, path);
6363
}
6464

65-
action<P, R>(path: string) {
65+
action<P, R>(path: string): ODataActionResource<P, R> {
6666
return ODataActionResource.fromResource<P, R>(this, path);
6767
}
6868

69-
function<P, R>(path: string) {
69+
function<P, R>(path: string): ODataFunctionResource<P, R> {
7070
return ODataFunctionResource.fromResource<P, R>(this, path);
7171
}
7272

projects/angular-odata/src/lib/schema/parsers/edm.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ const EdmParser = <T>(
2525
});
2626

2727
const Identity = (v: any) => v;
28-
const toNumber = (v: any) => Number(v);
29-
const toString = (v: any) => v.toString();
30-
const toBoolean = (v: any) => Boolean(v);
31-
const toDate = (v: any) => new Date(v);
28+
const toNumber = (v: any) => v && Number(v);
29+
const toString = (v: any) => v && v.toString();
30+
const toBoolean = (v: any) => v && Boolean(v);
31+
const toDate = (v: any) => v && new Date(v);
3232

3333
export const EDM_PARSERS: { [type: string]: FieldParser<any> } = {
3434
//Edm.Guid 16-byte (128-bit) unique identifier

0 commit comments

Comments
 (0)