Skip to content

Commit e86769c

Browse files
author
Brian Ojeda
committed
Fix DoubleObjectWithKey type; add respective test; Rename generics
1 parent 3e895af commit e86769c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// types and interfaces
33
// ----------------------------------------------------------------------------
44

5-
export type DoubledObject<Subject> = Subject;
5+
export type DoubledObject<T> = T;
66

7-
export type DoubledObjectWithKey<Key extends string> = {};
7+
export type DoubledObjectWithKey<T extends string> = { [K in T] };
88

9-
export type TestDouble<Function> = Function;
9+
export type TestDouble<T> = T;
1010

1111
export type TestDoubleConstructor<T> = Constructor<T>;
1212

@@ -156,7 +156,7 @@ export function object<T>(constructor: Constructor<T> ): DoubledObject<T>;
156156
* @param {Key[]} props Array of properties.
157157
* @returns {DoubledObjectWithKey<Key>}
158158
*/
159-
export function object<Key extends string>(props: Key[]): DoubledObjectWithKey<Key>;
159+
export function object<T extends string>(props: T[]): DoubledObjectWithKey<T>;
160160

161161
/**
162162
* Create a fake empty object that is cast as the generic using a Proxy object.

test/src/typescript/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ td.when(dog.bark()).thenReturn("bark!");
4343

4444
// td.object()
4545

46+
const cat = td.object(["scratch","meow"]);
47+
td.when(cat.scratch()).thenReturn("scratch!");
48+
td.when(cat.meow()).thenReturn("meow!");
49+
4650
const bird = td.object({ fly: function(){} });
4751
td.when(bird.fly()).thenReturn("fly!");
4852

0 commit comments

Comments
 (0)