Skip to content

Commit ea8883d

Browse files
Makes some changes but macros are not valid.
1 parent 56bcf7f commit ea8883d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

types/collectionsjs/collectionsjs-tests.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ collection.sortBy('name'); // $ExpectType Collection<{ name: string; age: number
5252
collection.stringify(); // $ExpectType string
5353
collection.sum('age'); // $ExpectType any
5454
collection.take(2); // $ExpectType Collection<{ name: string; age: number; }>
55-
collection.macro('addToMembers', (collection, n) => collection.map((collectionItem: any) => collectionItem + n)); // $ExpectType any
55+
56+
// Collection.macro('addToMembers', (collection, n) => collection.map((collectionItem: any) => collectionItem + n));
57+
// const collection2 = new Collection([1,2,3,4]).addToMembers(3);
58+
5659
collection.unique(stark => stark.age); // $ExpectType Collection<{ name: string; age: number; }>
5760
collection.values(); // $ExpectType Collection<{ name: string; age: number; }>
5861
collection.where('age', 14); // $ExpectType Collection<{ name: string; age: number; }>

types/collectionsjs/index.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,32 @@ export default class Collection<T> {
1616
count(): number;
1717
each(callback: (item: T) => void): Collection<T>;
1818
filter(callback: (item: T) => boolean): Collection<T>;
19-
find(item: any): number;
19+
find(item: T): number;
2020
first(callback?: ((item: T) => boolean)|null): T;
2121
flatten(deep?: boolean): Collection<T>;
2222
get(index: number): T;
2323
has(item: T): boolean;
2424
join(separator?: string): string;
2525
keys(): Collection<T>;
2626
last(callback?: ((item: T) => boolean)|null): T;
27-
map(callback: (item: T) => any): Collection<T>;
27+
map<R>(callback: (item: T) => R): Collection<T>;
2828
pluck(property: string): Collection<T>;
2929
push(item: T): Collection<T>;
30-
reduce(callback: (previous: T, current: T) => any, initial: any): any;
30+
reduce<R>(callback: (previous: R, current: T) => R, initial: R): R;
3131
reject(callback: (item: T) => boolean): Collection<T>;
32-
remove(item: any): boolean;
32+
remove(item: T): boolean;
3333
reverse(): Collection<T>;
3434
skip(count: number): Collection<T>;
3535
slice(start: number, end?: number): Collection<T>;
3636
sort(compare?: () => boolean): Collection<T>;
3737
sortBy(property: string, order?: string): Collection<T>;
3838
stringify(): string;
39-
sum(property?: string|null): any;
39+
sum(property: T extends object ? keyof T : never): number
4040
take(count: number): Collection<T>;
41-
macro(name: string, callback: (...args: any) => any): any;
41+
static macro(name: string, callback: (coll: Collection<unknown>, ...args: unknown[]) => unknown): void;
4242
unique(callback?: string|null|((item: T) => any)): Collection<T>;
4343
values(): Collection<T>;
44-
where(callback: ((item: T) => boolean)|string, value?: any): Collection<T>;
44+
where<K extends keyof T>(key: K, value: T[K]): Collection<T>
45+
where(callback: (item: T) => boolean): Collection<T>
4546
zip(array: T[]|Collection<T>): Collection<T>;
4647
}

0 commit comments

Comments
 (0)