-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wait to do typechecking when we have a schema
- Loading branch information
1 parent
6842836
commit 5a4f462
Showing
4 changed files
with
11 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 4 additions & 23 deletions
27
client/components/mma/savedArticles/models/SavedArticle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,18 @@ | ||
import { isObject } from '@guardian/libs'; | ||
|
||
export interface SavedArticle { | ||
id: string; | ||
shortUrl: string; | ||
date: Date; | ||
read: boolean; | ||
} | ||
|
||
// TODO - more extensible way of type guarding | ||
export function isSavedArticle(data: unknown): data is SavedArticle { | ||
const castObj = data as SavedArticle; | ||
return ( | ||
castObj !== null && | ||
castObj !== undefined && | ||
'id' in castObj && | ||
'shortUrl' in castObj && | ||
'date' in castObj && | ||
'read' in castObj | ||
); | ||
} | ||
export interface SavedArticlesResponse { | ||
version: number; | ||
articles: SavedArticle[]; | ||
} | ||
export function isSavedArticlesResponse( | ||
data: unknown, | ||
): data is SavedArticlesResponse { | ||
const castObj = data as SavedArticlesResponse; | ||
return ( | ||
castObj !== null && | ||
castObj !== undefined && | ||
'version' in castObj && | ||
'articles' in castObj && | ||
castObj.articles.reduce<boolean>((b, sv) => { | ||
return isSavedArticle(sv) && b; | ||
}, true) | ||
); | ||
// TODO - validate this properly when we have the schema | ||
return isObject(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters