From edfa6cda4eb3d838268dcdb676dedd0971b39f67 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Sat, 15 Feb 2020 04:33:17 +1100 Subject: [PATCH] fix types for jasmine: allow partial properties when using objects (#42363) Source reference from Jasmine: https://github.com/jasmine/jasmine/blob/a6a9550d1eacfc303d668d8c1901185b1e66bcf6/src/core/SpyFactory.js#L38-L49 --- types/jasmine/index.d.ts | 2 +- types/jasmine/jasmine-tests.ts | 30 ++++++++++++++++++++++++++++ types/jasmine/ts3.1/index.d.ts | 2 +- types/jasmine/ts3.1/jasmine-tests.ts | 30 ++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index 1e0105c807..3bab6a2ecd 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -207,7 +207,7 @@ declare namespace jasmine { type SpyObjPropertyNames = T extends undefined ? (ReadonlyArray | { [propertyName: string]: any }) : - (ReadonlyArray); + (ReadonlyArray | { [P in keyof T]?: T[P] }); /** * Configuration that can be used when configuring Jasmine via {@link jasmine.Env.configure} diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 8dd9f77141..1b77e13a69 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -1563,6 +1563,36 @@ describe("createSpyObj", function() { expect(spyObj.m()).toEqual(3); expect(spyObj.p).toEqual(4); }); + + it("allows methods and properties lists to omit entries from typed object", function() { + interface Template { + method1(): number; + method2(): void; + readonly property1: string; + property2: number; + } + const spyObj = jasmine.createSpyObj