File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -216,19 +216,14 @@ Discriminated unions advantages:
216216
217217 // TypeScript warns us with errors in calculateArea function
218218 const calculateArea = (shape : Shape ) => {
219- // Error - Switch is not exhaustive. Cases not matched: "triangle"
220- switch (shape .kind ) {
221- case ' circle' :
222- return Math .PI _ shape .radius \ * \ * 2 ;
223- case ' square' :
224- return shape .size _ shape .width ; // Error - Property 'width' does not exist on type 'square'
225- }
219+ // Error - Switch is not exhaustive. Cases not matched: "triangle"
220+ switch (shape .kind ) {
221+ case ' circle' :
222+ return Math .PI * shape .radius * * 2 ;
223+ case ' square' :
224+ return shape .size * shape .width ; // Error - Property 'width' does not exist on type 'square'
225+ }
226226 };
227-
228- ```
229-
230- ```
231-
232227 ```
233228
234229- Avoid code complexity introduced by [ flag variables] ( #type-union--boolean-flags ) .
You can’t perform that action at this time.
0 commit comments