( collection: C, key: K | string, value: V )
| 35 | value: V |
| 36 | ): C; |
| 37 | export function set<K, V, C extends Collection<K, V> | { [key: string]: V }>( |
| 38 | collection: C, |
| 39 | key: K | string, |
| 40 | value: V |
| 41 | ): C { |
| 42 | if (isProtoKey(key)) { |
| 43 | return collection; |
| 44 | } |
| 45 | |
| 46 | if (!isDataStructure(collection)) { |
| 47 | throw new TypeError( |
| 48 | 'Cannot update non-data-structure value: ' + collection |
| 49 | ); |
| 50 | } |
| 51 | if (isImmutable(collection)) { |
| 52 | // @ts-expect-error weird "set" here, |
| 53 | if (!collection.set) { |
| 54 | throw new TypeError( |
| 55 | 'Cannot update immutable value without .set() method: ' + collection |
| 56 | ); |
| 57 | } |
| 58 | // @ts-expect-error weird "set" here, |
| 59 | return collection.set(key, value); |
| 60 | } |
| 61 | // @ts-expect-error mix of key and string here. Probably need a more fine type here |
| 62 | if (hasOwnProperty.call(collection, key) && value === collection[key]) { |
| 63 | return collection; |
| 64 | } |
| 65 | const collectionCopy = shallowCopy(collection); |
| 66 | // @ts-expect-error mix of key and string here. Probably need a more fine type here |
| 67 | collectionCopy[key] = value; |
| 68 | return collectionCopy; |
| 69 | } |
no test coverage detected