-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(examples): 2021-09-20 linter warnings batch 17 / 26; part 2
1. Added a user-defined type guard to check for `BambooHarvest` types on the front-end. 2. Additional runtime type checks during data type conversion so that if we get invalid input it speaks up against it specifically instead of using `any` types and generic crashes. Fixes #2092 Co-authored-by: Peter Somogyvari <peter.somogyvari@accenture.com> Signed-off-by: adrianbatuto <adrian.batuto@accenture.com> Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
- Loading branch information
1 parent
a462bbc
commit acdcec6
Showing
4 changed files
with
77 additions
and
14 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
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
12 changes: 12 additions & 0 deletions
12
examples/cactus-example-supply-chain-frontend/src/app/bamboo-harvest/is-bamboo-harvest.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BambooHarvest } from "@hyperledger/cactus-example-supply-chain-business-logic-plugin"; | ||
|
||
export function isBambooHarvest(x: unknown): x is BambooHarvest { | ||
return ( | ||
!!x && | ||
typeof (x as BambooHarvest).id === "string" && | ||
typeof (x as BambooHarvest).location === "string" && | ||
typeof (x as BambooHarvest).startedAt === "string" && | ||
typeof (x as BambooHarvest).endedAt === "string" && | ||
typeof (x as BambooHarvest).harvester === "string" | ||
); | ||
} |