mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #664 from vagarenko/master
Added generic typing and converted to TS 0.9 module
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/// <reference path="underscore.d.ts" />
|
||||
import _ = require("underscore")
|
||||
|
||||
declare var $;
|
||||
declare function alert(any);
|
||||
|
||||
_.each([1, 2, 3], (num) => alert(num));
|
||||
_.each({ one: 1, two: 2, three: 3 }, (num, key) => alert(num));
|
||||
@@ -205,7 +206,7 @@ var moe2 = { name: 'moe' };
|
||||
moe2 === _.identity(moe);
|
||||
|
||||
var genie;
|
||||
_(3).times(function(n){ genie.grantWishNumber(n); });
|
||||
_(3).times(function (n) { genie.grantWishNumber(n); });
|
||||
|
||||
_.random(0, 100);
|
||||
|
||||
@@ -240,10 +241,8 @@ 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;
|
||||
|
||||
_.countBy([1, 2, 3], function (item) {
|
||||
return item % 2;
|
||||
});
|
||||
Vendored
+203
-207
@@ -5,8 +5,8 @@
|
||||
|
||||
|
||||
interface UnderscoreWrappedObject {
|
||||
value () : any;
|
||||
filter(arg?) : any;
|
||||
value(): any;
|
||||
filter(arg?): any;
|
||||
}
|
||||
|
||||
interface TemplateSettings {
|
||||
@@ -15,218 +15,214 @@ interface TemplateSettings {
|
||||
escape?: RegExp;
|
||||
}
|
||||
|
||||
interface ListIterator {
|
||||
(value, key, list?): void;
|
||||
interface ListIterator<T, TResult> {
|
||||
(value: T, index: number, list?: List<T>): TResult;
|
||||
}
|
||||
|
||||
interface ObjectIterator {
|
||||
(element, index, list?): void;
|
||||
interface ObjectIterator<T, TResult> {
|
||||
(element: T, key: string, list?: any): TResult;
|
||||
}
|
||||
|
||||
interface Collection<T> { }
|
||||
|
||||
// Common interface between Arrays and jQuery objects
|
||||
interface List {
|
||||
[index: number]: any;
|
||||
interface List<T> extends Collection<T> {
|
||||
[index: number]: T;
|
||||
length: number;
|
||||
}
|
||||
|
||||
interface UnderscoreStatic {
|
||||
(arg?:any) : any;
|
||||
|
||||
/****
|
||||
Collections
|
||||
*****/
|
||||
each(list: List, iterator: ListIterator, context?: any): any[];
|
||||
each(object: any, iterator: ObjectIterator, context?: any): any[];
|
||||
forEach(list: List, iterator: ObjectIterator, context?: any): any[];
|
||||
forEach(object: any, iterator: ListIterator, context?: any): any[];
|
||||
|
||||
map(list: List, iterator: ListIterator, context?: any): any[];
|
||||
map(object: any, iterator: ObjectIterator, context?: any): any[];
|
||||
collect(list: List, iterator: ListIterator, context?: any): any[];
|
||||
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;
|
||||
include(list: any, value: any): bool;
|
||||
include(list: List, value: any): bool;
|
||||
|
||||
invoke(list: List, methodName: string, arguments: any[]): any;
|
||||
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;
|
||||
|
||||
/****
|
||||
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: 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[];
|
||||
|
||||
/****
|
||||
Functions
|
||||
*****/
|
||||
bind(func: (...as : any[]) => any, context: any, ...arguments: any[]): () => any;
|
||||
bindAll(object: any, ...methodNames: string[]): any;
|
||||
memoize(func: any, hashFunction?: any): any;
|
||||
defer(func: () => any);
|
||||
delay(func: any, wait: number, ...arguments: any[]): any;
|
||||
delay(func: any, ...arguments: any[]): any;
|
||||
throttle(func: any, wait: number): any;
|
||||
debounce(func: any, wait: number, immediate?: bool): any;
|
||||
once(func: any): any;
|
||||
after(count: number, func: any): any;
|
||||
wrap(func: (...as : any[]) => any, wrapper: any): () => any;
|
||||
compose(...functions: any[]): any;
|
||||
|
||||
/****
|
||||
Objects
|
||||
*****/
|
||||
keys(object: any): any[];
|
||||
values(object: any): any[];
|
||||
pairs(object: any): any[];
|
||||
invert(object: any): any;
|
||||
|
||||
functions(object: any): string[];
|
||||
methods(object: any): string[];
|
||||
|
||||
extend(destination: any, ...sources: any[]): any;
|
||||
pick(object: any, ...keys: string[]): any;
|
||||
omit(object: any, ...keys: string[]): any;
|
||||
defaults(object: any, ...defaults: any[]): any;
|
||||
clone(object: any): any;
|
||||
tap(object: any, interceptor: (...as : any[]) => any): any;
|
||||
has(object: any, key: string): bool;
|
||||
isEqual(object: any, other: any): bool;
|
||||
isEmpty(object: any): bool;
|
||||
isElement(object: any): bool;
|
||||
isArray(object: any): bool;
|
||||
isObject(value: any): bool;
|
||||
isArguments(object: any): bool;
|
||||
isFunction(object: any): bool;
|
||||
isString(object: any): bool;
|
||||
isNumber(object: any): bool;
|
||||
isFinite(object: any): bool;
|
||||
isBoolean(object: any): bool;
|
||||
isDate(object: any): bool;
|
||||
isRegExp(object: any): bool;
|
||||
isNaN(object: any): bool;
|
||||
isNull(object: any): bool;
|
||||
isUndefined(value: any): bool;
|
||||
|
||||
/****
|
||||
Utility
|
||||
*****/
|
||||
noConflict(): any;
|
||||
identity(value: any): any;
|
||||
times(n: number, iterator: (index : number) => void, context?: any): void;
|
||||
random(min: number, max: number): number;
|
||||
mixin(object: any): void;
|
||||
uniqueId(prefix: string): string;
|
||||
uniqueId(): number;
|
||||
escape(str: string): string;
|
||||
result(object: any, property: string): any;
|
||||
templateSettings: TemplateSettings;
|
||||
template(templateString: string, data?: any, settings?: any): (...data: any[]) => string;
|
||||
|
||||
/****
|
||||
Chaining
|
||||
*****/
|
||||
chain(object: any): UnderscoreWrappedObject;
|
||||
interface Dictionary<T> extends Collection<T> {
|
||||
[index: string]: T;
|
||||
}
|
||||
|
||||
declare var _: UnderscoreStatic;
|
||||
declare module "underscore" {
|
||||
function underscore(arg?: any): any;
|
||||
|
||||
module underscore {
|
||||
/****
|
||||
Collections
|
||||
*****/
|
||||
export function each<T>(list: List<T>, iterator: ListIterator<T, void>, context?: any): void;
|
||||
export function each<T>(object: Dictionary<T>, iterator: ObjectIterator<T, void>, context?: any): void;
|
||||
export function forEach<T>(list: List<T>, iterator: ListIterator<T, void>, context?: any): void;
|
||||
export function forEach<T>(object: Dictionary<T>, iterator: ObjectIterator<T, void>, context?: any): void;
|
||||
|
||||
export function map<T, TResult>(list: List<T>, iterator: ListIterator<T, TResult>, context?: any): TResult[];
|
||||
export function map<T, TResult>(object: Dictionary<T>, iterator: ObjectIterator<T, TResult>, context?: any): TResult[];
|
||||
export function collect<T, TResult>(list: List<T>, iterator: ListIterator<T, TResult>, context?: any): TResult[];
|
||||
export function collect<T, TResult>(object: Dictionary<T>, iterator: ObjectIterator<T, TResult>, context?: any): TResult[];
|
||||
|
||||
export function reduce<T, TResult>(list: Collection<T>, iterator: (prev: TResult, curr: T) => TResult, memo: TResult, context?: any): TResult;
|
||||
export function inject<T, TResult>(list: Collection<T>, iterator: (prev: TResult, curr: T) => TResult, memo: TResult, context?: any): TResult;
|
||||
|
||||
export function reduceRight<T, TResult>(list: Collection<T>, iterator: (prev: TResult, curr: T) => TResult, memo: TResult, context?: any): TResult;
|
||||
export function foldr<T, TResult>(list: Collection<T>, iterator: (prev: TResult, curr: T) => TResult, memo: TResult, context?: any): TResult;
|
||||
|
||||
export function find<T>(list: Collection<T>, iterator: (x: T) => boolean, context?: any): T;
|
||||
export function detect<T>(list: Collection<T>, iterator: (x: T) => boolean, context?: any): T;
|
||||
|
||||
export function filter<T>(list: Collection<T>, iterator: (x: T) => boolean, context?: any): T[];
|
||||
export function select<T>(list: Collection<T>, iterator: (x: T) => boolean, context?: any): T[];
|
||||
|
||||
export function where<T>(list: Collection<T>, properties: any): T[];
|
||||
|
||||
export function reject<T>(list: Collection<T>, iterator: (x: T) => boolean, context?: any): T[];
|
||||
|
||||
export function all<T>(list: Collection<T>, iterator: (x: T) => boolean, context?: any): boolean;
|
||||
export function every<T>(list: Collection<T>, iterator: (x: T) => boolean, context?: any): boolean;
|
||||
|
||||
export function any<T>(list: Collection<T>, iterator?: (x: T) => boolean, context?: any): boolean;
|
||||
export function some<T>(list: Collection<T>, iterator?: (x: T) => boolean, context?: any): boolean;
|
||||
|
||||
export function contains<T>(list: Collection<T>, value: T): boolean;
|
||||
export function include<T>(list: Collection<T>, value: T): boolean;
|
||||
|
||||
export function invoke<T>(list: Collection<T>, methodName: string, ...arguments: any[]): any;
|
||||
|
||||
export function pluck<T>(list: Collection<T>, propertyName: string): any[];
|
||||
|
||||
export function max<T>(list: Collection<T>, iterator?: (x: T) => any, context?: any): T;
|
||||
|
||||
export function min<T>(list: Collection<T>, iterator?: (x: T) => any, context?: any): T;
|
||||
|
||||
export function sortBy<T>(list: List<T>, iterator?: (x: T) => any, context?: any): T[];
|
||||
export function sortBy<T>(list: any, iterator?: (x: T) => any, context?: any): T[];
|
||||
export function sortBy<T>(list: List<T>, iterator: string, context?: any): T[];
|
||||
export function sortBy<T>(list: any, iterator: string, context?: any): T[];
|
||||
|
||||
export function groupBy<T>(list: List<T>, iterator?: (x: T) => any, context?: any): Dictionary<List<T>>;
|
||||
export function groupBy<T>(list: any, iterator?: (x: T) => any, context?: any): Dictionary<List<T>>;
|
||||
export function groupBy<T>(list: List<T>, iterator: string, context?: any): Dictionary<List<T>>;
|
||||
export function groupBy<T>(list: any, iterator: string, context?: any): Dictionary<List<T>>;
|
||||
|
||||
export function countBy<T>(list: List<T>, iterator?: (x: T) => any, context?: any): Dictionary<List<number>>;
|
||||
export function countBy<T>(list: any, iterator?: (x: T) => any, context?: any): Dictionary<List<number>>;
|
||||
export function countBy<T>(list: List<T>, iterator: string, context?: any): Dictionary<List<number>>;
|
||||
export function countBy<T>(list: any, iterator: string, context?: any): Dictionary<List<number>>;
|
||||
|
||||
export function shuffle<T>(list: Collection<T>): T[];
|
||||
|
||||
export function toArray<T>(list: Collection<T>): T[];
|
||||
|
||||
export function size<T>(list: Collection<T>): number;
|
||||
|
||||
/****
|
||||
Arrays
|
||||
*****/
|
||||
export function first<T>(array: List<T>): T;
|
||||
export function first<T>(array: List<T>, n: number): T[];
|
||||
export function head<T>(array: List<T>): T;
|
||||
export function head<T>(array: List<T>, n: number): T[];
|
||||
export function take<T>(array: List<T>): T;
|
||||
export function take<T>(array: List<T>, n: number): T[];
|
||||
|
||||
export function initial<T>(array: List<T>, n?: number): T[];
|
||||
|
||||
export function last<T>(array: List<T>): T;
|
||||
export function last<T>(array: List<T>, n: number): T[];
|
||||
|
||||
export function rest<T>(array: List<T>, n?: number): T[];
|
||||
export function tail<T>(array: List<T>, n?: number): T[];
|
||||
export function drop<T>(array: List<T>, n?: number): T[];
|
||||
|
||||
export function compact<T>(array: List<T>): T[];
|
||||
|
||||
export function flatten(array: any[], shallow?: boolean): any[];
|
||||
|
||||
export function without<T>(array: List<T>, ...values: T[]): T[];
|
||||
|
||||
export function union<T>(...arrays: List<T>[]): T[];
|
||||
|
||||
export function intersection<T>(...arrays: List<T>[]): T[];
|
||||
|
||||
export function difference<T>(array: List<T>, ...others: List<T>[]): T[];
|
||||
|
||||
export function uniq<T>(array: List<T>, isSorted?: boolean, iterator?: (x: T) => any): T[];
|
||||
export function unique<T>(array: List<T>, isSorted?: boolean, iterator?: (x: T) => any): T[];
|
||||
|
||||
export function zip(...arrays: any[]): any[];
|
||||
|
||||
export function object(list: any[], values?: any): any;
|
||||
|
||||
export function indexOf<T>(array: List<T>, value: T, isSorted?: boolean): number;
|
||||
export function indexOf<T>(array: List<T>, value: T, startFrom: number): number;
|
||||
|
||||
export function lastIndexOf<T>(array: List<T>, value: T, fromIndex?: number): number;
|
||||
|
||||
export function sortedIndex<T>(list: List<T>, value: T, iterator?: (x: T) => any, context?: any): number;
|
||||
|
||||
export function range(stop: number): any[];
|
||||
export function range(start: number, stop: number, step?: number): any[];
|
||||
|
||||
/****
|
||||
Functions
|
||||
*****/
|
||||
export function bind(func: (...as: any[]) => any, context: any, ...arguments: any[]): () => any;
|
||||
export function bindAll(object: any, ...methodNames: string[]): any;
|
||||
export function memoize(func: any, hashFunction?: any): any;
|
||||
export function defer(func: () => any);
|
||||
export function delay(func: any, wait: number, ...arguments: any[]): any;
|
||||
export function delay(func: any, ...arguments: any[]): any;
|
||||
export function throttle(func: any, wait: number): any;
|
||||
export function debounce(func: any, wait: number, immediate?: boolean): any;
|
||||
export function once(func: any): any;
|
||||
export function after(count: number, func: any): any;
|
||||
export function wrap(func: (...as: any[]) => any, wrapper: any): () => any;
|
||||
export function compose(...functions: any[]): any;
|
||||
|
||||
/****
|
||||
Objects
|
||||
*****/
|
||||
export function keys(object: any): string[];
|
||||
export function values<T>(object: Dictionary<T>): T[];
|
||||
export function pairs(object: any): any[];
|
||||
export function invert(object: any): any;
|
||||
export function functions(object: any): string[];
|
||||
export function methods(object: any): string[];
|
||||
export function extend(destination: any, ...sources: any[]): any;
|
||||
export function pick(object: any, ...keys: string[]): any;
|
||||
export function omit(object: any, ...keys: string[]): any;
|
||||
export function defaults(object: any, ...defaults: any[]): any;
|
||||
export function clone(object: any): any;
|
||||
export function tap(object: any, interceptor: (...as: any[]) => any): any;
|
||||
export function has(object: any, key: string): boolean;
|
||||
export function isEqual(object: any, other: any): boolean;
|
||||
export function isEmpty(object: any): boolean;
|
||||
export function isElement(object: any): boolean;
|
||||
export function isArray(object: any): boolean;
|
||||
export function isObject(value: any): boolean;
|
||||
export function isArguments(object: any): boolean;
|
||||
export function isFunction(object: any): boolean;
|
||||
export function isString(object: any): boolean;
|
||||
export function isNumber(object: any): boolean;
|
||||
export function isFinite(object: any): boolean;
|
||||
export function isBoolean(object: any): boolean;
|
||||
export function isDate(object: any): boolean;
|
||||
export function isRegExp(object: any): boolean;
|
||||
export function isNaN(object: any): boolean;
|
||||
export function isNull(object: any): boolean;
|
||||
export function isUndefined(value: any): boolean;
|
||||
|
||||
/****
|
||||
Utility
|
||||
*****/
|
||||
export function noConflict(): any;
|
||||
export function identity(value: any): any;
|
||||
export function times(n: number, iterator: (index: number) => void , context?: any): void;
|
||||
export function random(min: number, max: number): number;
|
||||
export function mixin(object: any): void;
|
||||
export function uniqueId(prefix: string): string;
|
||||
export function uniqueId(): number;
|
||||
export function escape(str: string): string;
|
||||
export function result(object: any, property: string): any;
|
||||
export var templateSettings: TemplateSettings;
|
||||
export function template(templateString: string, data?: any, settings?: any): (...data: any[]) => string;
|
||||
|
||||
/****
|
||||
Chaining
|
||||
*****/
|
||||
export function chain(object: any): UnderscoreWrappedObject;
|
||||
}
|
||||
|
||||
export = underscore;
|
||||
}
|
||||
Reference in New Issue
Block a user