mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-07 16:30:12 +08:00
Merge pull request #227 from Diullei/master
Fix #225 - Underscorejs definition errors
This commit is contained in:
@@ -11,6 +11,7 @@ _.map({ one: 1, two: 2, three: 3 }, (num, key) => num * 3);
|
||||
var sum = _.reduce([1, 2, 3], (memo, num) => memo + num, 0);
|
||||
|
||||
var list = [[0, 1], [2, 3], [4, 5]];
|
||||
|
||||
var flat = _.reduceRight(list, (a, b) => a.concat(b), []);
|
||||
|
||||
var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0);
|
||||
@@ -79,7 +80,7 @@ _.range(0);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var func = function (greeting) { return greeting + ': ' + this.name };
|
||||
var func = function (greeting?) { return greeting + ': ' + this.name };
|
||||
func = _.bind(func, { name: 'moe' }, 'hi');
|
||||
func();
|
||||
|
||||
@@ -118,7 +119,7 @@ var render = () => alert("rendering...");
|
||||
var renderNotes = _.after(notes.length, render);
|
||||
_.each(notes, (note) => note.asyncSave({ success: renderNotes }));
|
||||
|
||||
var hello = function (name) { return "hello: " + name; };
|
||||
var hello = function (name?) { return "hello: " + name; };
|
||||
hello = _.wrap(hello, (func) => { return "before, " + func("moe") + ", after"; });
|
||||
hello();
|
||||
|
||||
@@ -194,7 +195,7 @@ _.isNaN(undefined);
|
||||
_.isNull(null);
|
||||
_.isNull(undefined);
|
||||
|
||||
_.isUndefined(window.missingVariable);
|
||||
_.isUndefined((<any>window).missingVariable);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -238,3 +239,11 @@ _.templateSettings = {
|
||||
var template2 = _.template("Hello {{ name }}!");
|
||||
template2({ name: "Mustache" });
|
||||
_.template("Using 'with': <%= data.answer %>", { answer: 'no' }, { variable: 'data' });
|
||||
|
||||
// fix: http://stackoverflow.com/questions/14585324/how-to-use-underscore-lib-from-definitelytyped-with-typescript
|
||||
// fix: https://github.com/borisyankov/DefinitelyTyped/issues/225
|
||||
declare var _: UnderscoreStatic;
|
||||
|
||||
_.countBy([1,2,3], function(item) {
|
||||
return item%2;
|
||||
});
|
||||
Vendored
+41
-1
@@ -6,6 +6,7 @@
|
||||
|
||||
interface UnderscoreWrappedObject {
|
||||
value () : any;
|
||||
filter(arg?) : any;
|
||||
}
|
||||
|
||||
interface TemplateSettings {
|
||||
@@ -29,6 +30,7 @@ interface List {
|
||||
}
|
||||
|
||||
interface UnderscoreStatic {
|
||||
(arg?:any) : any;
|
||||
|
||||
/****
|
||||
Collections
|
||||
@@ -44,27 +46,42 @@ interface UnderscoreStatic {
|
||||
collect(object: any, iterator: ObjectIterator, context?: any): any[];
|
||||
|
||||
reduce(list: List, iterator: any, memo: any, context?: any): any[];
|
||||
reduce(list: any[], iterator: any, memo: any, context?: any): any[];
|
||||
inject(list: List, iterator: any, memo: any, context?: any): any[];
|
||||
inject(list: any[], iterator: any, memo: any, context?: any): any[];
|
||||
foldl(list: List, iterator: any, memo: any, context?: any): any[];
|
||||
foldl(list: any[], iterator: any, memo: any, context?: any): any[];
|
||||
|
||||
reduceRight(list: List, iterator: any, memo: any, context?: any): any[];
|
||||
reduceRight(list: any[], iterator: any, memo: any, context?: any): any[];
|
||||
foldr(list: List, iterator: any, memo: any, context?: any): any[];
|
||||
foldr(list: any[], iterator: any, memo: any, context?: any): any[];
|
||||
|
||||
find(list: List, iterator: any, context?: any): any;
|
||||
find(list: any[], iterator: any, context?: any): any;
|
||||
detect(list: List, iterator: any, context?: any): any;
|
||||
detect(list: any[], iterator: any, context?: any): any;
|
||||
|
||||
filter(list: List, iterator: any, context?: any): any[];
|
||||
filter(list: any[], iterator: any, context?: any): any[];
|
||||
select(list: List, iterator: any, context?: any): any[];
|
||||
select(list: any[], iterator: any, context?: any): any[];
|
||||
|
||||
where(list: List, properties: any): any[];
|
||||
where(list: any[], properties: any): any[];
|
||||
|
||||
reject(list: List, iterator: any, context?: any): any[];
|
||||
reject(list: any[], iterator: any, context?: any): any[];
|
||||
|
||||
all(list: List, iterator: any, context?: any): bool;
|
||||
all(list: any[], iterator: any, context?: any): bool;
|
||||
every(list: List, iterator: any, context?: any): bool;
|
||||
every(list: any[], iterator: any, context?: any): bool;
|
||||
|
||||
any(list: List, iterator?: any, context?: any): bool;
|
||||
any(list: any[], iterator?: any, context?: any): bool;
|
||||
some(list: List, iterator?: any, context?: any): bool;
|
||||
some(list: any[], iterator?: any, context?: any): bool;
|
||||
|
||||
contains(list: any, value: any): bool;
|
||||
contains(list: List, value: any): bool;
|
||||
@@ -75,11 +92,17 @@ interface UnderscoreStatic {
|
||||
invoke(object: any, methodName: string, ...arguments: any[]): any;
|
||||
|
||||
pluck(list: List, propertyName: string): string[];
|
||||
pluck(list: any[], propertyName: string): string[];
|
||||
max(list: List, iterator?: any, context?: any): any;
|
||||
max(list: any[], iterator?: any, context?: any): any;
|
||||
min(list: List, iterator?: any, context?: any): any;
|
||||
min(list: any[], iterator?: any, context?: any): any;
|
||||
sortBy(list: List, iterator?: any, context?: any): any;
|
||||
sortBy(list: any[], iterator?: any, context?: any): any;
|
||||
groupBy(list: List, iterator: any): any;
|
||||
groupBy(list: any[], iterator: any): any;
|
||||
countBy(list: List, iterator: any): any;
|
||||
countBy(list: any[], iterator: any): any;
|
||||
shuffle(list: any[]): any[];
|
||||
toArray(list: any): any[];
|
||||
size(list: any): number;
|
||||
@@ -88,32 +111,49 @@ interface UnderscoreStatic {
|
||||
Arrays
|
||||
*****/
|
||||
first(array: List, n?: number): any;
|
||||
first(array: any[], n?: number): any;
|
||||
head(array: List, n?: number): any;
|
||||
head(array: any[], n?: number): any;
|
||||
take(array: List, n?: number): any;
|
||||
take(array: any[], n?: number): any;
|
||||
|
||||
initial(array: List, n?: number): any[];
|
||||
initial(array: any[], n?: number): any[];
|
||||
|
||||
last(array: List, n?: number): any;
|
||||
last(array: any[], n?: number): any;
|
||||
|
||||
rest(array: List, n?: number): any[];
|
||||
rest(array: any[], n?: number): any[];
|
||||
tail(array: List, n?: number): any[];
|
||||
tail(array: any[], n?: number): any[];
|
||||
drop(array: List, n?: number): any[];
|
||||
drop(array: any[], n?: number): any[];
|
||||
|
||||
compact(array: any[]): any[];
|
||||
flatten(array: List, shallow?: bool): any[];
|
||||
flatten(array: any[], shallow?: bool): any[];
|
||||
without(array: List, ...values: any[]): any[];
|
||||
without(array: any[], ...values: any[]): any[];
|
||||
union(...arrays: any[][]): any[];
|
||||
intersection(...arrays: any[][]): any[];
|
||||
difference(array: List, ...others: any[][]): any[];
|
||||
difference(array: any[], ...others: any[][]): any[];
|
||||
|
||||
uniq(array: List, isSorted?: bool, iterator?: any): any[];
|
||||
uniq(array: any[], isSorted?: bool, iterator?: any): any[];
|
||||
unique(array: List, isSorted?: bool, iterator?: any): any[];
|
||||
unique(array: any[], isSorted?: bool, iterator?: any): any[];
|
||||
|
||||
zip(...arrays: any[]): any[];
|
||||
object(list: List, values: any[]): any;
|
||||
object(list: List, values?: any[]): any;
|
||||
object(list: any[], values?: any[]): any;
|
||||
indexOf(array: List, value: any, isSorted?: bool): number;
|
||||
indexOf(array: any[], value: any, isSorted?: bool): number;
|
||||
lastIndexOf(array: List, value: any, fromIndex?: number): number;
|
||||
lastIndexOf(array: any[], value: any, fromIndex?: number): number;
|
||||
sortedIndex(list: List, valueL: any, iterator?: any): number;
|
||||
sortedIndex(list: any[], valueL: any, iterator?: any): number;
|
||||
range(stop: number): any[];
|
||||
range(start: number, stop: number, step?: number): any[];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user