From b45d55ae2812f791fd99f6c537997cebb9317593 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Fri, 18 Oct 2024 14:01:11 +0200 Subject: [PATCH 1/3] fix: added entry about complex types in functions parameters --- contributingGuides/STYLE.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/contributingGuides/STYLE.md b/contributingGuides/STYLE.md index 304811332916..b744598ecf82 100644 --- a/contributingGuides/STYLE.md +++ b/contributingGuides/STYLE.md @@ -24,6 +24,7 @@ - [Refs](#refs) - [Other Expensify Resources on TypeScript](#other-expensify-resources-on-typescript) - [Default value for inexistent IDs](#default-value-for-inexistent-IDs) + - [Extract complex types](#extract-complex-types) - [Naming Conventions](#naming-conventions) - [Type names](#type-names) - [Prop callbacks](#prop-callbacks) @@ -492,6 +493,30 @@ const foo = report?.reportID ?? '-1'; report ? report.reportID : '-1'; ``` +### Extract complex types + +All complex types, such as objects and callbacks in function parameters, should be extracted into separate type definitions. + +``` ts +// BAD +function foo(param1: string, param2: {id: string}) {...}; + +// BAD +function foo(param1: string, param2: (value: string) => void) {...}; + +// GOOD +type Data = { + id: string; +}; + +function foo(param1: string, param2: Data) {...}; + +// GOOD +type Callback = (value: string) => void + +function foo(param1: string, param2: Callback) {...}; +``` + ## Naming Conventions ### Type names From 44f08d73ceb77925d10e518e692c06cad298789c Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Mon, 21 Oct 2024 09:06:03 +0200 Subject: [PATCH 2/3] fix: resolve comment --- contributingGuides/STYLE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contributingGuides/STYLE.md b/contributingGuides/STYLE.md index b744598ecf82..45228034b8c2 100644 --- a/contributingGuides/STYLE.md +++ b/contributingGuides/STYLE.md @@ -495,9 +495,9 @@ report ? report.reportID : '-1'; ### Extract complex types -All complex types, such as objects and callbacks in function parameters, should be extracted into separate type definitions. +Complex types, such as objects in function parameters, should be extracted into separate type definitions. Callbacks in function parameters should be extracted if they have possibility to be reused somewhere else. -``` ts +```ts // BAD function foo(param1: string, param2: {id: string}) {...}; From 676ef8c9d9341e7c26d09074184037b725a90954 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Mon, 21 Oct 2024 15:26:52 +0200 Subject: [PATCH 3/3] fix: replace to Blazej copy suggestion --- contributingGuides/STYLE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributingGuides/STYLE.md b/contributingGuides/STYLE.md index 45228034b8c2..e6660d848129 100644 --- a/contributingGuides/STYLE.md +++ b/contributingGuides/STYLE.md @@ -495,7 +495,7 @@ report ? report.reportID : '-1'; ### Extract complex types -Complex types, such as objects in function parameters, should be extracted into separate type definitions. Callbacks in function parameters should be extracted if they have possibility to be reused somewhere else. +Advanced data types, such as objects within function parameters, should be separated into their own type definitions. Callbacks in function parameters should be extracted if there's a possibility they could be reused somewhere else. ```ts // BAD