{"id":22281154,"url":"https://github.com/voodoocreation/ts-deepmerge","last_synced_at":"2025-05-15T13:06:31.151Z","repository":{"id":36475286,"uuid":"227504226","full_name":"voodoocreation/ts-deepmerge","owner":"voodoocreation","description":"A TypeScript deep merge function with automatically inferred types.","archived":false,"fork":false,"pushed_at":"2025-05-02T01:23:59.000Z","size":626,"stargazers_count":132,"open_issues_count":2,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-02T01:32:01.767Z","etag":null,"topics":["deep-merge","deepmerge","inferred-types","merge","recursive","recursive-merge","ts-merge","typescript","typescript-merge"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voodoocreation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-12T02:36:00.000Z","updated_at":"2025-05-02T01:21:22.000Z","dependencies_parsed_at":"2024-06-18T13:41:51.334Z","dependency_job_id":"b324d1a5-341b-497f-ab35-4f6348cf8576","html_url":"https://github.com/voodoocreation/ts-deepmerge","commit_stats":{"total_commits":37,"total_committers":3,"mean_commits":"12.333333333333334","dds":"0.18918918918918914","last_synced_commit":"91f227872d770234cbaf3f24cab9f5d04972c9b0"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voodoocreation%2Fts-deepmerge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voodoocreation%2Fts-deepmerge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voodoocreation%2Fts-deepmerge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voodoocreation%2Fts-deepmerge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voodoocreation","download_url":"https://codeload.github.com/voodoocreation/ts-deepmerge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254346624,"owners_count":22055808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-merge","deepmerge","inferred-types","merge","recursive","recursive-merge","ts-merge","typescript","typescript-merge"],"created_at":"2024-12-03T16:15:25.286Z","updated_at":"2025-05-15T13:06:26.142Z","avatar_url":"https://github.com/voodoocreation.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/ts-deepmerge)](https://www.npmjs.com/package/ts-deepmerge)\n\nTypeScript Deep Merge\n=====================\n\nA deep merge function that automatically infers the return type based on your input,\nwithout mutating the source objects.\n\nObjects and arrays will be merged, but values such as numbers and strings will be overwritten.\n\nAll merging/overwriting occurs in the order of the arguments you provide the function with.\n\nBoth ESM and CommonJS are supported by this package.\n\n\nUsage\n-----\n```typescript jsx\nimport { merge } from \"ts-deepmerge\";\n\nconst obj1 = {\n  a: {\n    a: 1\n  }\n};\n\nconst obj2 = {\n  b: {\n    a: 2,\n    b: 2\n  }\n};\n\nconst obj3 = {\n  a: {\n    b: 3\n  },\n  b: {\n    b: 3,\n    c: 3\n  },\n  c: 3\n};\n\nconst result = merge(obj1, obj2, obj3);\n```\n\nThe value of the above `result` is:\n```json\n{\n  \"a\": {\n    \"a\": 1,\n    \"b\": 3\n  },\n  \"b\": {\n    \"a\": 2,\n    \"b\": 3,\n    \"c\": 3\n  },\n  \"c\": 3\n}\n```\n\n### With options\n\nIf you would like to provide options to change the merge behaviour, you can use the `.withOptions` method:\n```typescript\nimport { merge } from \"ts-deepmerge\";\n\nconst obj1 = {\n  array: [\"A\"],\n};\n\nconst obj2 = {\n  array: [\"B\"],\n}\n\nconst result = merge.withOptions(\n  { mergeArrays: false },\n  obj1,\n  obj2\n);\n```\n\nThe value of the above `result` is:\n```json\n{\n  \"array\": [\"B\"]\n}\n```\n\nAll options have JSDoc descriptions [in its source](/src/index.ts#L87).\n\n\n### When working with generic declared types/interfaces\n\nThere's currently a limitation with the inferred return type that `ts-deepmerge` offers, where it's\nunable to take the order of the objects/properties into consideration due to the nature of accepting\nan infinite number of objects to merge as args and what TypeScript currently offers to infer the types.\nThe primary use case for the inferred return type is for basic object primitives, to offer something\nmore useful as the return type, which does work for a lot of cases.\n\nIf you're working with generic declared types though, this can cause the inferred return type to not align\nwith what you may expect, as it currently detects every possible value and combines them as a union type.\nWhen working with declared types, and you know what the final type will align to, simply use the `as` keyword\nas shown in the example below:\n```typescript\ninterface IObj {\n  a: string;\n  b: string;\n}\n\nconst obj1: IObj = { a: \"1\", b: \"2\", };\nconst obj2: Partial\u003cIObj\u003e = { a: \"1\" };\n\nconst result = merge(obj1, obj2) as IObj;\n```\n\nMore context can be found in [this issue](https://github.com/voodoocreation/ts-deepmerge/issues/30).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoodoocreation%2Fts-deepmerge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoodoocreation%2Fts-deepmerge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoodoocreation%2Fts-deepmerge/lists"}