In my Angular 2 project, I am utilizing Interfaces and have implemented User Defined Type Guards:
grid-metadata.ts
export interface GridMetadata {
activity: string;
createdAt: object;
totalReps: number;
updatedAt: object;
}
grid.service.ts
...
function isGridMetadata(obj: any): obj is GridMetadata {
[ 'activity', 'createdAt', 'totalReps', 'updatedAt' ].every((prop) => {
if (obj.hasOwnProperty(prop) === false) return false;
});
return typeof obj.activity === 'string' &&
obj.createdAt.hasOwnProperty('.sv') &&
obj.createdAt['.sv'] === 'timestamp' &&
typeof obj.totalReps === 'number' &&
obj.updatedAt.hasOwnProperty('.sv') &&
obj.updatedAt['.sv'] === 'timestamp' ?
true :
false;
}
...
What is the best practice for organizing Interfaces in terms of file structure? Should they be kept in separate files or grouped together in an interface
or util
directory/file?
When it comes to shared User Defined Type Guards, what is the recommended approach for organization? Would it be beneficial to combine the Interface and UDTG in a single file due to their relationship, or keep all UDTGs in a shared module?
I am struggling to find clear examples or widely accepted conventions for structuring my project.