From 2628189ece421579bc3dfedb2e11e5fb766fd675 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Wed, 29 Jan 2020 06:52:14 +0100 Subject: [PATCH] Add more principles. --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36cd902..4e96f60 100644 --- a/README.md +++ b/README.md @@ -217,12 +217,16 @@ const guessWhatAgain = sum({}, []); // -> 0 _Bad 👎🏻_ ```javascript -function sum(a: number, b: number): number { +function sum(a: number, b: number): ?number { + // Covering the case when we don't do transpilation and/or Flow type checks in JS. + if (typeof a !== 'number' && typeof b !== 'number') { + return undefined; + } return a + b; } -// This one fails during the transpilation/compilation. -const guessWhat = sum([], {}); +// This one should fails during the transpilation/compilation. +const guessWhat = sum([], {}); // -> undefined ``` ### 💩 You need to have an unreachable piece of code