From ff0b28e5bf568416bdce0bb9b3980df4f9b701cf Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 26 Jul 2023 11:13:00 -0600 Subject: [PATCH] Improve instructions for migrating away from underscore --- contributingGuides/TS_STYLE.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/contributingGuides/TS_STYLE.md b/contributingGuides/TS_STYLE.md index 965ce24a5357..6d8d4a446428 100644 --- a/contributingGuides/TS_STYLE.md +++ b/contributingGuides/TS_STYLE.md @@ -489,7 +489,23 @@ declare module "external-library-name" { - If you're migrating a module that doesn't have a default implementation (i.e. `index.ts`, e.g. `getPlatform`), convert `index.website.js` to `index.ts`. Without `index.ts`, TypeScript cannot get type information where the module is imported. -- Deprecate the usage of `underscore`. Use the corresponding methods from `lodash`. eslint: [`no-restricted-imports`](https://eslint.org/docs/latest/rules/no-restricted-imports) +- Deprecate the usage of `underscore`. Use vanilla methods from JS instead. Only use `lodash` when there is no easy vanilla alternative (eg. `lodashMerge`). eslint: [`no-restricted-imports`](https://eslint.org/docs/latest/rules/no-restricted-imports) + +```ts +// BAD +var arr = []; +_.each(arr, () => {}); + +// GOOD +var arr = []; +arr.forEach(() => {}); + +// BAD +lodashGet(object, ['foo'], 'bar'); + +// GOOD +object?.foo ?? 'bar'; +``` - Found type bugs. Now what?