(
collection:
| Collection<K, unknown>
| Array<unknown>
| { [key: PropertyKey]: unknown },
key: K
)
| 34 | | { [key: PropertyKey]: unknown }, |
| 35 | >(collection: C, key: K): C; |
| 36 | export function remove<K>( |
| 37 | collection: |
| 38 | | Collection<K, unknown> |
| 39 | | Array<unknown> |
| 40 | | { [key: PropertyKey]: unknown }, |
| 41 | key: K |
| 42 | ) { |
| 43 | if (!isDataStructure(collection)) { |
| 44 | throw new TypeError( |
| 45 | 'Cannot update non-data-structure value: ' + collection |
| 46 | ); |
| 47 | } |
| 48 | if (isImmutable(collection)) { |
| 49 | // @ts-expect-error weird "remove" here, |
| 50 | if (!collection.remove) { |
| 51 | throw new TypeError( |
| 52 | 'Cannot update immutable value without .remove() method: ' + collection |
| 53 | ); |
| 54 | } |
| 55 | // @ts-expect-error weird "remove" here, |
| 56 | return collection.remove(key); |
| 57 | } |
| 58 | // @ts-expect-error assert that key is a string, a number or a symbol here |
| 59 | if (!hasOwnProperty.call(collection, key)) { |
| 60 | return collection; |
| 61 | } |
| 62 | const collectionCopy = shallowCopy(collection); |
| 63 | if (Array.isArray(collectionCopy)) { |
| 64 | // @ts-expect-error assert that key is a number here |
| 65 | collectionCopy.splice(key, 1); |
| 66 | } else { |
| 67 | // @ts-expect-error assert that key is a string, a number or a symbol here |
| 68 | delete collectionCopy[key]; |
| 69 | } |
| 70 | return collectionCopy; |
| 71 | } |
no test coverage detected