From 8d90d403627f949dc8bf1bf32dc33c918b55f6eb Mon Sep 17 00:00:00 2001 From: Matthias Kunnen Date: Sun, 23 Aug 2020 10:35:16 +0200 Subject: [PATCH] fix: DeepPartial with any and {[k: string]: any} (#6581) * test: Test DeepPartial with any and {[k: string]: any} This tests #6580. * fix: DeepPartial with any and {[k: string]: any} Fixes #6580. --- src/common/DeepPartial.ts | 2 +- test/github-issues/6580/entity/Comment.ts | 4 ++++ test/github-issues/6580/issue-6580.ts | 24 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/github-issues/6580/entity/Comment.ts create mode 100644 test/github-issues/6580/issue-6580.ts diff --git a/src/common/DeepPartial.ts b/src/common/DeepPartial.ts index c318088d54..370c1f5f2d 100644 --- a/src/common/DeepPartial.ts +++ b/src/common/DeepPartial.ts @@ -5,5 +5,5 @@ export type DeepPartial = { [P in keyof T]?: T[P] extends Array ? Array> : T[P] extends ReadonlyArray ? ReadonlyArray> : - DeepPartial + DeepPartial | T[P] }; diff --git a/test/github-issues/6580/entity/Comment.ts b/test/github-issues/6580/entity/Comment.ts new file mode 100644 index 0000000000..1ef8a1139b --- /dev/null +++ b/test/github-issues/6580/entity/Comment.ts @@ -0,0 +1,4 @@ +export class Comment { + any: any; + object: {[k: string]: any}; +} diff --git a/test/github-issues/6580/issue-6580.ts b/test/github-issues/6580/issue-6580.ts new file mode 100644 index 0000000000..d309ad411e --- /dev/null +++ b/test/github-issues/6580/issue-6580.ts @@ -0,0 +1,24 @@ +import {DeepPartial} from "../../../src"; +import {Comment} from "./entity/Comment"; + +describe("github issues > #6580 DeepPartial does not handle `any` and `{[k: string]}`", () => { + + function attemptDeepPartial(entityLike: DeepPartial): void { + } + + it("DeepPartial should correctly handle any", () => { + attemptDeepPartial({ + any: { + foo: 'bar', + } + }) + }); + + it("DeepPartial should correctly handle {[k: string]: any}", () => { + attemptDeepPartial({ + object: { + foo: 'bar' + }, + }) + }); +});