From 92627555c6b0d56c96a95e31780e3015b3e637e9 Mon Sep 17 00:00:00 2001 From: Vijay A Date: Sat, 4 Sep 2021 22:10:28 +0530 Subject: refactoring: Use 'ifUndefined*' consistently. Added some error checking --- src/models/RecipePreview.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/models/RecipePreview.ts') diff --git a/src/models/RecipePreview.ts b/src/models/RecipePreview.ts index 351ecf765..4d2cc8450 100644 --- a/src/models/RecipePreview.ts +++ b/src/models/RecipePreview.ts @@ -1,5 +1,13 @@ // @flow +interface IRecipePreview { + id: string; + name: string; + icon: string; + featured: boolean; + aliases: string[]; +} + export default class RecipePreview { id: string = ''; @@ -11,9 +19,13 @@ export default class RecipePreview { aliases: string[] = []; - constructor(data: { id: any; }) { + constructor(data: IRecipePreview) { + if (!data) { + throw Error('RecipePreview config not valid'); + } + if (!data.id) { - throw Error('RecipePreview requires Id'); + throw Error(`RecipePreview '${data.name}' requires Id`); } Object.assign(this, data); -- cgit v1.2.3-54-g00ecf