From 705b88949c821cf2ff38daee9000f850a53372d3 Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Wed, 13 Mar 2019 10:33:42 -0600 Subject: [PATCH 1/2] Wrap lodash functions to avoid exporting lodash type defs --- src/services/objects.ts | 13 +++++++++--- src/services/predicate/lodash_predicates.ts | 23 ++++++++++++++------- src/services/utils.ts | 23 ++++++++++++++++++--- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/services/objects.ts b/src/services/objects.ts index c36f4996d58..fa75474eba9 100644 --- a/src/services/objects.ts +++ b/src/services/objects.ts @@ -1,4 +1,11 @@ -import get from 'lodash/get'; -import omit from 'lodash/omit'; +import _get from 'lodash/get'; +import _omit from 'lodash/omit'; -export { get, omit }; +// wrap the lodash functions to avoid having lodash's TS type definition from being +// exported, which can conflict with the lodash namespace if other versions are used + +export const get = (object: {}, path: string[] | string, defaultValue?: any) => + _get(object, path, defaultValue); + +export const omit = (object: {} | null | undefined, paths: string[]) => + _omit(object, paths); diff --git a/src/services/predicate/lodash_predicates.ts b/src/services/predicate/lodash_predicates.ts index 5e65c3149ee..168839c360d 100644 --- a/src/services/predicate/lodash_predicates.ts +++ b/src/services/predicate/lodash_predicates.ts @@ -1,8 +1,17 @@ -import isFunction from 'lodash/isFunction'; -import isArray from 'lodash/isArray'; -import isString from 'lodash/isString'; -import isBoolean from 'lodash/isBoolean'; -import isNumber from 'lodash/isNumber'; -import isNaN from 'lodash/isNaN'; +import _isFunction from 'lodash/isFunction'; +import _isArray from 'lodash/isArray'; +import _isString from 'lodash/isString'; +import _isBoolean from 'lodash/isBoolean'; +import _isNumber from 'lodash/isNumber'; +import _isNaN from 'lodash/isNaN'; -export { isFunction, isArray, isString, isBoolean, isNumber, isNaN }; +// wrap the lodash functions to avoid having lodash's TS type definition from being +// exported, which can conflict with the lodash namespace if other versions are used + +// tslint:disable-next-line:ban-types +export const isFunction = (value: any): value is Function => _isFunction(value); +export const isArray = (value: any): value is any[] => _isArray(value); +export const isString = (value: any): value is string => _isString(value); +export const isBoolean = (value: any): value is boolean => _isBoolean(value); +export const isNumber = (value: any): value is number => _isNumber(value); +export const isNaN = (value: any) => _isNaN(value); diff --git a/src/services/utils.ts b/src/services/utils.ts index 90823fde200..a109b84a9ad 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -1,7 +1,24 @@ -import times from 'lodash/times'; -import memoize from 'lodash/memoize'; +import _times from 'lodash/times'; +import _memoize from 'lodash/memoize'; -export { times, memoize }; +// wrap the lodash functions to avoid having lodash's TS type definition from being +// exported, which can conflict with the lodash namespace if other versions are used + +export function times(count: number): number[]; +export function times(count: number, iteratee: (index: number) => T): T[]; +export function times(count: number, iteratee?: (index: number) => T) { + if (iteratee === undefined) { + return _times(count); + } + return _times(count, iteratee); +} + +export function memoize any>( + func: T, + resolver?: (...args: any[]) => any +): (...args: Parameters) => ReturnType { + return _memoize(func, resolver); +} export const browserTick = (callback: FrameRequestCallback) => { requestAnimationFrame(callback); From 6064e003fe8f3d3495870e358bb996312292e83c Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Wed, 13 Mar 2019 10:40:47 -0600 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a10deff14..544c06d6ea4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ - Allow toasts in `EuiGlobalToastList` to override `toastLifeTimeMs` ([#1720](https://github.com/elastic/eui/pull/1720)) +**Bug fixes** + +- Removed all `lodash` imports in `eui.d.ts` to avoid namespace pollution ([#1723](https://github.com/elastic/eui/pull/1723)) + ## [`9.3.0`](https://github.com/elastic/eui/tree/v9.3.0) - Added `footerLink` and `showToolTips` to `EuiNavDrawer` and added `EuiNavDrawerGroup` ([#1701](https://github.com/elastic/eui/pull/1701))