mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Update tests
1. Accept baselines 2. Fix APISample_watcher 3. Switch checker to use JSDOc for isWeak Some of the baselines seem incorrect or weirder than before.
This commit is contained in:
parent
2433f56815
commit
c9da70560f
@ -9392,8 +9392,10 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
// A type is 'weak' if it is an object type with at least one optional property
|
||||
// and no required properties or index signatures
|
||||
/**
|
||||
* A type is 'weak' if it is an object type with at least one optional property
|
||||
* and no required properties or index signatures
|
||||
*/
|
||||
function isWeak(type: Type) {
|
||||
let props = getPropertiesOfType(type);
|
||||
return type.flags & TypeFlags.Object &&
|
||||
|
||||
@ -11,7 +11,7 @@ declare var fs: {
|
||||
existsSync(path: string): boolean;
|
||||
readdirSync(path: string): string[];
|
||||
readFileSync(filename: string, encoding?: string): string;
|
||||
writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void;
|
||||
writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; } | string): void;
|
||||
watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: { mtime: Date }, prev: { mtime: Date }) => void): void;
|
||||
};
|
||||
declare var path: any;
|
||||
|
||||
@ -247,7 +247,7 @@ function goo(x: X) {
|
||||
|
||||
x.y;
|
||||
>x.y : string
|
||||
>x : Y
|
||||
>x : X & Y
|
||||
>y : string
|
||||
}
|
||||
x;
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,14): error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
|
||||
Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<State>'.
|
||||
Type 'State | 1' is not assignable to type 'State'.
|
||||
Type '1' is not assignable to type 'State'.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(24,61): error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
|
||||
Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
|
||||
Type 'State | 1' is not assignable to type 'StrategicState'.
|
||||
Type '1' is not assignable to type 'StrategicState'.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(29,70): error TS7025: Generator implicitly has type 'IterableIterator<any>' because it does not yield any values. Consider supplying a return type.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(32,42): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
|
||||
Type argument candidate 'State' is not a valid type argument because it is not a supertype of candidate '1'.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,62): error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
|
||||
Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts (4 errors) ====
|
||||
@ -33,11 +34,11 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err
|
||||
}
|
||||
|
||||
export const Nothing: Strategy<State> = strategy("Nothing", function* (state: State) {
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
|
||||
!!! error TS2322: Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<State>'.
|
||||
!!! error TS2322: Type 'State | 1' is not assignable to type 'State'.
|
||||
!!! error TS2322: Type '1' is not assignable to type 'State'.
|
||||
~~~~~~~~
|
||||
!!! error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
|
||||
!!! error TS2345: Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
|
||||
!!! error TS2345: Type 'State | 1' is not assignable to type 'StrategicState'.
|
||||
!!! error TS2345: Type '1' is not assignable to type 'StrategicState'.
|
||||
yield 1;
|
||||
return state;
|
||||
});
|
||||
@ -55,8 +56,9 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck63.ts(36,14): err
|
||||
});
|
||||
|
||||
export const Nothing3: Strategy<State> = strategy("Nothing", function* (state: State) {
|
||||
~~~~~~~~
|
||||
!!! error TS2322: Type '(a: State | 1) => IterableIterator<State | 1>' is not assignable to type 'Strategy<State>'.
|
||||
~~~~~~~~
|
||||
!!! error TS2345: Argument of type '(state: State) => IterableIterator<State | 1>' is not assignable to parameter of type '(a: StrategicState) => IterableIterator<StrategicState>'.
|
||||
!!! error TS2345: Type 'IterableIterator<State | 1>' is not assignable to type 'IterableIterator<StrategicState>'.
|
||||
yield state;
|
||||
return 1;
|
||||
});
|
||||
@ -69,8 +69,8 @@ var b: { Foo2: Derived; }
|
||||
>Derived : Derived
|
||||
|
||||
var r = true ? a : b; // ok
|
||||
>r : { Foo?: Base; }
|
||||
>true ? a : b : { Foo?: Base; }
|
||||
>r : { Foo?: Base; } | { Foo2: Derived; }
|
||||
>true ? a : b : { Foo?: Base; } | { Foo2: Derived; }
|
||||
>true : true
|
||||
>a : { Foo?: Base; }
|
||||
>b : { Foo2: Derived; }
|
||||
|
||||
@ -69,8 +69,8 @@ var b: { Foo2?: Derived; }
|
||||
>Derived : Derived
|
||||
|
||||
var r = true ? a : b; // ok
|
||||
>r : { Foo2?: Derived; }
|
||||
>true ? a : b : { Foo2?: Derived; }
|
||||
>r : { Foo: Base; } | { Foo2?: Derived; }
|
||||
>true ? a : b : { Foo: Base; } | { Foo2?: Derived; }
|
||||
>true : true
|
||||
>a : { Foo: Base; }
|
||||
>b : { Foo2?: Derived; }
|
||||
|
||||
@ -1,12 +1,15 @@
|
||||
tests/cases/conformance/jsx/file.tsx(23,8): error TS2322: Type '{ x: "0"; }' is not assignable to type 'Attribs1'.
|
||||
Types of property 'x' are incompatible.
|
||||
Type '"0"' is not assignable to type 'number'.
|
||||
tests/cases/conformance/jsx/file.tsx(24,8): error TS2339: Property 'y' does not exist on type 'Attribs1'.
|
||||
tests/cases/conformance/jsx/file.tsx(25,8): error TS2339: Property 'y' does not exist on type 'Attribs1'.
|
||||
tests/cases/conformance/jsx/file.tsx(24,8): error TS2322: Type '{ y: 0; }' is not assignable to type 'Attribs1'.
|
||||
Weak type 'Attribs1' has no properties in common with '{ y: 0; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(25,8): error TS2322: Type '{ y: "foo"; }' is not assignable to type 'Attribs1'.
|
||||
Weak type 'Attribs1' has no properties in common with '{ y: "foo"; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(26,8): error TS2322: Type '{ x: "32"; }' is not assignable to type 'Attribs1'.
|
||||
Types of property 'x' are incompatible.
|
||||
Type '"32"' is not assignable to type 'number'.
|
||||
tests/cases/conformance/jsx/file.tsx(27,8): error TS2339: Property 'var' does not exist on type 'Attribs1'.
|
||||
tests/cases/conformance/jsx/file.tsx(27,8): error TS2322: Type '{ var: "10"; }' is not assignable to type 'Attribs1'.
|
||||
Weak type 'Attribs1' has no properties in common with '{ var: "10"; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(29,1): error TS2322: Type '{}' is not assignable to type '{ reqd: string; }'.
|
||||
Property 'reqd' is missing in type '{}'.
|
||||
tests/cases/conformance/jsx/file.tsx(30,8): error TS2322: Type '{ reqd: 10; }' is not assignable to type '{ reqd: string; }'.
|
||||
@ -44,10 +47,12 @@ tests/cases/conformance/jsx/file.tsx(30,8): error TS2322: Type '{ reqd: 10; }' i
|
||||
!!! error TS2322: Type '"0"' is not assignable to type 'number'.
|
||||
<test1 y={0} />; // Error, no property "y"
|
||||
~~~~~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'Attribs1'.
|
||||
!!! error TS2322: Type '{ y: 0; }' is not assignable to type 'Attribs1'.
|
||||
!!! error TS2322: Weak type 'Attribs1' has no properties in common with '{ y: 0; }'.
|
||||
<test1 y="foo" />; // Error, no property "y"
|
||||
~~~~~~~
|
||||
!!! error TS2339: Property 'y' does not exist on type 'Attribs1'.
|
||||
!!! error TS2322: Type '{ y: "foo"; }' is not assignable to type 'Attribs1'.
|
||||
!!! error TS2322: Weak type 'Attribs1' has no properties in common with '{ y: "foo"; }'.
|
||||
<test1 x="32" />; // Error, "32" is not number
|
||||
~~~~~~
|
||||
!!! error TS2322: Type '{ x: "32"; }' is not assignable to type 'Attribs1'.
|
||||
@ -55,7 +60,8 @@ tests/cases/conformance/jsx/file.tsx(30,8): error TS2322: Type '{ reqd: 10; }' i
|
||||
!!! error TS2322: Type '"32"' is not assignable to type 'number'.
|
||||
<test1 var="10" />; // Error, no 'var' property
|
||||
~~~~~~~~
|
||||
!!! error TS2339: Property 'var' does not exist on type 'Attribs1'.
|
||||
!!! error TS2322: Type '{ var: "10"; }' is not assignable to type 'Attribs1'.
|
||||
!!! error TS2322: Weak type 'Attribs1' has no properties in common with '{ var: "10"; }'.
|
||||
|
||||
<test2 />; // Error, missing reqd
|
||||
~~~~~~~~~
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
tests/cases/conformance/jsx/file.tsx(11,22): error TS2339: Property 'bar' does not exist on type 'IntrinsicAttributes & { ref?: string; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(11,22): error TS2322: Type '{ bar: "world"; }' is not assignable to type 'IntrinsicAttributes & { ref?: string; }'.
|
||||
Weak type 'IntrinsicAttributes & { ref?: string; }' has no properties in common with '{ bar: "world"; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/react.d.ts (0 errors) ====
|
||||
@ -27,6 +28,7 @@ tests/cases/conformance/jsx/file.tsx(11,22): error TS2339: Property 'bar' does n
|
||||
// Should be an OK
|
||||
var x = <MyComponent bar='world' />;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2339: Property 'bar' does not exist on type 'IntrinsicAttributes & { ref?: string; }'.
|
||||
!!! error TS2322: Type '{ bar: "world"; }' is not assignable to type 'IntrinsicAttributes & { ref?: string; }'.
|
||||
!!! error TS2322: Weak type 'IntrinsicAttributes & { ref?: string; }' has no properties in common with '{ bar: "world"; }'.
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
tests/cases/conformance/jsx/file.tsx(17,7): error TS2339: Property 'x' does not exist on type '{ q?: number; }'.
|
||||
tests/cases/conformance/jsx/file.tsx(17,7): error TS2322: Type '{ x: 10; }' is not assignable to type '{ q?: number; }'.
|
||||
Weak type '{ q?: number; }' has no properties in common with '{ x: 10; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsx/file.tsx (1 errors) ====
|
||||
@ -20,7 +21,8 @@ tests/cases/conformance/jsx/file.tsx(17,7): error TS2339: Property 'x' does not
|
||||
var Obj2: Obj2type;
|
||||
<Obj2 x={10} />; // Error
|
||||
~~~~~~
|
||||
!!! error TS2339: Property 'x' does not exist on type '{ q?: number; }'.
|
||||
!!! error TS2322: Type '{ x: 10; }' is not assignable to type '{ q?: number; }'.
|
||||
!!! error TS2322: Weak type '{ q?: number; }' has no properties in common with '{ x: 10; }'.
|
||||
|
||||
interface Obj3type {
|
||||
new(n: string): { x: number; };
|
||||
|
||||
@ -1,907 +0,0 @@
|
||||
tests/cases/compiler/underscoreTest1_underscoreTests.ts(252,66): error TS2345: Argument of type '{ variable: string; }' is not assignable to parameter of type 'TemplateSettings'.
|
||||
Weak type 'TemplateSettings' has no properties in common with '{ variable: string; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/underscoreTest1_underscoreTests.ts (1 errors) ====
|
||||
/// <reference path="underscoreTest1_underscore.ts" />
|
||||
|
||||
declare var $;
|
||||
declare function alert(x: string): void;
|
||||
|
||||
_.each([1, 2, 3], (num) => alert(num.toString()));
|
||||
_.each({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => alert(value.toString()));
|
||||
|
||||
_.map([1, 2, 3], (num) => num * 3);
|
||||
_.map({ one: 1, two: 2, three: 3 }, (value: number, key?: string) => value * 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);
|
||||
|
||||
var evens = _.filter([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0);
|
||||
|
||||
var listOfPlays = [{ title: "Cymbeline", author: "Shakespeare", year: 1611 }, { title: "The Tempest", author: "Shakespeare", year: 1611 }, { title: "Other", author: "Not Shakespeare", year: 2012 }];
|
||||
_.where(listOfPlays, { author: "Shakespeare", year: 1611 });
|
||||
|
||||
var odds = _.reject([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0);
|
||||
|
||||
_.all([true, 1, null, 'yes'], _.identity);
|
||||
|
||||
_.any([null, 0, 'yes', false]);
|
||||
|
||||
_.contains([1, 2, 3], 3);
|
||||
|
||||
_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
|
||||
|
||||
var stooges = [{ name: 'moe', age: 40 }, { name: 'larry', age: 50 }, { name: 'curly', age: 60 }];
|
||||
_.pluck(stooges, 'name');
|
||||
|
||||
_.max(stooges, (stooge) => stooge.age);
|
||||
|
||||
var numbers = [10, 5, 100, 2, 1000];
|
||||
_.min(numbers);
|
||||
|
||||
_.sortBy([1, 2, 3, 4, 5, 6], (num) => Math.sin(num));
|
||||
|
||||
|
||||
// not sure how this is typechecking at all.. Math.floor(e) is number not string..?
|
||||
_([1.3, 2.1, 2.4]).groupBy((e: number, i?: number, list?: number[]) => Math.floor(e));
|
||||
_.groupBy([1.3, 2.1, 2.4], (num: number) => Math.floor(num));
|
||||
_.groupBy(['one', 'two', 'three'], 'length');
|
||||
|
||||
_.countBy([1, 2, 3, 4, 5], (num) => num % 2 == 0 ? 'even' : 'odd');
|
||||
|
||||
_.shuffle([1, 2, 3, 4, 5, 6]);
|
||||
|
||||
// (function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
|
||||
|
||||
_.size({ one: 1, two: 2, three: 3 });
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
_.first([5, 4, 3, 2, 1]);
|
||||
_.initial([5, 4, 3, 2, 1]);
|
||||
_.last([5, 4, 3, 2, 1]);
|
||||
_.rest([5, 4, 3, 2, 1]);
|
||||
_.compact([0, 1, false, 2, '', 3]);
|
||||
|
||||
_.flatten([1, 2, 3, 4]);
|
||||
_.flatten([1, [2]]);
|
||||
|
||||
// typescript doesn't like the elements being different
|
||||
_.flatten([1, [2], [3, [[4]]]]);
|
||||
_.flatten([1, [2], [3, [[4]]]], true);
|
||||
_.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
|
||||
_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
|
||||
_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
|
||||
_.difference([1, 2, 3, 4, 5], [5, 2, 10]);
|
||||
_.uniq([1, 2, 1, 3, 1, 4]);
|
||||
_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
|
||||
_.object(['moe', 'larry', 'curly'], [30, 40, 50]);
|
||||
_.object([['moe', 30], ['larry', 40], ['curly', 50]]);
|
||||
_.indexOf([1, 2, 3], 2);
|
||||
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
|
||||
_.sortedIndex([10, 20, 30, 40, 50], 35);
|
||||
_.range(10);
|
||||
_.range(1, 11);
|
||||
_.range(0, 30, 5);
|
||||
_.range(0, 30, 5);
|
||||
_.range(0);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var func = function (greeting) { return greeting + ': ' + this.name };
|
||||
// need a second var otherwise typescript thinks func signature is the above func type,
|
||||
// instead of the newly returned _bind => func type.
|
||||
var func2 = _.bind(func, { name: 'moe' }, 'hi');
|
||||
func2();
|
||||
|
||||
var buttonView = {
|
||||
label: 'underscore',
|
||||
onClick: function () { alert('clicked: ' + this.label); },
|
||||
onHover: function () { alert('hovering: ' + this.label); }
|
||||
};
|
||||
_.bindAll(buttonView);
|
||||
$('#underscore_button').bind('click', buttonView.onClick);
|
||||
|
||||
var fibonacci = _.memoize(function (n) {
|
||||
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
|
||||
});
|
||||
|
||||
var log = _.bind((message?: string, ...rest: string[]) => { }, Date);
|
||||
_.delay(log, 1000, 'logged later');
|
||||
|
||||
_.defer(function () { alert('deferred'); });
|
||||
|
||||
var updatePosition = () => alert('updating position...');
|
||||
var throttled = _.throttle(updatePosition, 100);
|
||||
$(null).scroll(throttled);
|
||||
|
||||
var calculateLayout = () => alert('calculating layout...');
|
||||
var lazyLayout = _.debounce(calculateLayout, 300);
|
||||
$(null).resize(lazyLayout);
|
||||
|
||||
var createApplication = () => alert('creating application...');
|
||||
var initialize = _.once(createApplication);
|
||||
initialize();
|
||||
initialize();
|
||||
|
||||
var notes: any[];
|
||||
var render = () => alert("rendering...");
|
||||
var renderNotes = _.after(notes.length, render);
|
||||
_.each(notes, (note) => note.asyncSave({ success: renderNotes }));
|
||||
|
||||
var hello = function (name) { return "hello: " + name; };
|
||||
hello = _.wrap(hello, (func, arg) => { return "before, " + func(arg) + ", after"; });
|
||||
hello("moe");
|
||||
|
||||
var greet = function (name) { return "hi: " + name; };
|
||||
var exclaim = function (statement) { return statement + "!"; };
|
||||
var welcome = _.compose(exclaim, greet);
|
||||
welcome('moe');
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
_.keys({ one: 1, two: 2, three: 3 });
|
||||
_.values({ one: 1, two: 2, three: 3 });
|
||||
_.pairs({ one: 1, two: 2, three: 3 });
|
||||
_.invert({ Moe: "Moses", Larry: "Louis", Curly: "Jerome" });
|
||||
_.functions(_);
|
||||
_.extend({ name: 'moe' }, { age: 50 });
|
||||
_.pick({ name: 'moe', age: 50, userid: 'moe1' }, 'name', 'age');
|
||||
_.omit({ name: 'moe', age: 50, userid: 'moe1' }, 'userid');
|
||||
|
||||
var iceCream = { flavor: "chocolate" };
|
||||
_.defaults(iceCream, { flavor: "vanilla", sprinkles: "lots" });
|
||||
|
||||
_.clone({ name: 'moe' });
|
||||
|
||||
_.chain([1, 2, 3, 200])
|
||||
.filter(function (num) { return num % 2 == 0; })
|
||||
.tap(<any>alert)
|
||||
.map(function (num) { return num * num })
|
||||
.value();
|
||||
|
||||
_.has({ a: 1, b: 2, c: 3 }, "b");
|
||||
|
||||
var moe = { name: 'moe', luckyNumbers: [13, 27, 34] };
|
||||
var clone = { name: 'moe', luckyNumbers: [13, 27, 34] };
|
||||
moe == clone;
|
||||
_.isEqual(moe, clone);
|
||||
|
||||
_.isEmpty([1, 2, 3]);
|
||||
_.isEmpty({});
|
||||
|
||||
_.isElement($('body')[0]);
|
||||
|
||||
(function () { return _.isArray(arguments); })();
|
||||
_.isArray([1, 2, 3]);
|
||||
|
||||
_.isObject({});
|
||||
_.isObject(1);
|
||||
|
||||
|
||||
// (() => { return _.isArguments(arguments); })(1, 2, 3);
|
||||
_.isArguments([1, 2, 3]);
|
||||
|
||||
_.isFunction(alert);
|
||||
|
||||
_.isString("moe");
|
||||
|
||||
_.isNumber(8.4 * 5);
|
||||
|
||||
_.isFinite(-101);
|
||||
|
||||
_.isFinite(-Infinity);
|
||||
|
||||
_.isBoolean(null);
|
||||
|
||||
_.isDate(new Date());
|
||||
|
||||
_.isRegExp(/moe/);
|
||||
|
||||
_.isNaN(NaN);
|
||||
isNaN(undefined);
|
||||
_.isNaN(undefined);
|
||||
|
||||
_.isNull(null);
|
||||
_.isNull(undefined);
|
||||
|
||||
_.isUndefined((<any>null).missingVariable);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var underscore = _.noConflict();
|
||||
|
||||
var moe2 = { name: 'moe' };
|
||||
moe2 === _.identity(moe);
|
||||
|
||||
var genie;
|
||||
|
||||
_.times(3, function (n) { genie.grantWishNumber(n); });
|
||||
|
||||
_.random(0, 100);
|
||||
|
||||
_.mixin({
|
||||
capitalize: function (string) {
|
||||
return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
|
||||
}
|
||||
});
|
||||
(<any>_("fabio")).capitalize();
|
||||
|
||||
_.uniqueId('contact_');
|
||||
|
||||
_.escape('Curly, Larry & Moe');
|
||||
|
||||
var object = { cheese: 'crumpets', stuff: function () { return 'nonsense'; } };
|
||||
_.result(object, 'cheese');
|
||||
|
||||
_.result(object, 'stuff');
|
||||
|
||||
var compiled = _.template("hello: <%= name %>");
|
||||
compiled({ name: 'moe' });
|
||||
var list2 = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
|
||||
_.template(list2, { people: ['moe', 'curly', 'larry'] });
|
||||
var template = _.template("<b><%- value %></b>");
|
||||
template({ value: '<script>' });
|
||||
var compiled2 = _.template("<% print('Hello ' + epithet); %>");
|
||||
compiled2({ epithet: "stooge" });
|
||||
_.templateSettings = {
|
||||
interpolate: /\{\{(.+?)\}\}/g
|
||||
};
|
||||
var template2 = _.template("Hello {{ name }}!");
|
||||
template2({ name: "Mustache" });
|
||||
_.template("Using 'with': <%= data.answer %>", { answer: 'no' }, { variable: 'data' });
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '{ variable: string; }' is not assignable to parameter of type 'TemplateSettings'.
|
||||
!!! error TS2345: Weak type 'TemplateSettings' has no properties in common with '{ variable: string; }'.
|
||||
==== tests/cases/compiler/underscoreTest1_underscore.ts (0 errors) ====
|
||||
interface Dictionary<T> {
|
||||
[x: string]: T;
|
||||
}
|
||||
|
||||
interface Iterator<T, U> {
|
||||
(value: T, index: any, list: any): U;
|
||||
}
|
||||
|
||||
interface Reducer<T, U> {
|
||||
(accumulator: U, value: T, index: any, list: any): U;
|
||||
}
|
||||
|
||||
interface Tuple2<T0, T1> extends Array<any> {
|
||||
0: T0;
|
||||
1: T1;
|
||||
}
|
||||
|
||||
interface Tuple3<T0, T1, T2> extends Array<any> {
|
||||
0: T0;
|
||||
1: T1;
|
||||
2: T2;
|
||||
}
|
||||
|
||||
interface Tuple4<T0, T1, T2, T3> extends Array<any> {
|
||||
0: T0;
|
||||
1: T1;
|
||||
2: T2;
|
||||
3: T3;
|
||||
}
|
||||
|
||||
module Underscore {
|
||||
export interface WrappedObject<T> {
|
||||
keys(): string[];
|
||||
values(): any[];
|
||||
pairs(): any[][];
|
||||
invert(): any;
|
||||
functions(): string[];
|
||||
methods(): string[];
|
||||
extend(...sources: any[]): T;
|
||||
pick(...keys: string[]): T;
|
||||
omit(...keys: string[]): T;
|
||||
defaults(...defaults: any[]): T;
|
||||
clone(): T;
|
||||
tap(interceptor: (object: T) => void): T;
|
||||
has(key: string): boolean;
|
||||
isEqual(other: T): boolean;
|
||||
isEmpty(): boolean;
|
||||
isElement(): boolean;
|
||||
isArray(): boolean;
|
||||
isObject(): boolean;
|
||||
isArguments(): boolean;
|
||||
isFunction(): boolean;
|
||||
isString(): boolean;
|
||||
isNumber(): boolean;
|
||||
isFinite(): boolean;
|
||||
isBoolean(): boolean;
|
||||
isDate(): boolean;
|
||||
isRegExp(): boolean;
|
||||
isNaN(): boolean;
|
||||
isNull(): boolean;
|
||||
isUndefined(): boolean;
|
||||
value(): T;
|
||||
}
|
||||
|
||||
export interface WrappedFunction<T extends Function> extends WrappedObject<T> {
|
||||
bind(object: any): T;
|
||||
bind(object: any, ...args: any[]): Function;
|
||||
bindAll(...methodNames: string[]): T;
|
||||
partial(...args: any[]): Function;
|
||||
memoize(hashFunction?: Function): T;
|
||||
delay(wait: number, ...args: any[]): number;
|
||||
defer(...args: any[]): number;
|
||||
throttle(wait: number): T;
|
||||
debounce(wait: number, immediate?: boolean): T;
|
||||
once(): T;
|
||||
wrap(wrapper: (func: T, ...args: any[]) => any): T;
|
||||
compose(...funcs: Function[]): Function;
|
||||
}
|
||||
|
||||
export interface WrappedArray<T> extends WrappedObject<Array<T>> {
|
||||
each(iterator: Iterator<T, void>, context?: any): void;
|
||||
forEach(iterator: Iterator<T, void>, context?: any): void;
|
||||
map<U>(iterator: Iterator<T, U>, context?: any): U[];
|
||||
collect<U>(iterator: Iterator<T, U>, context?: any): U[];
|
||||
reduce(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduce<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldl(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldl<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
inject(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
inject<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
reduceRight(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduceRight<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldr(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldr<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
find(iterator: Iterator<T, boolean>, context?: any): T;
|
||||
detect(iterator: Iterator<T, boolean>, context?: any): T;
|
||||
filter(iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
select(iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
where(properties: Object): T[];
|
||||
findWhere(properties: Object): T;
|
||||
reject(iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
every(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
all(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
some(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
any(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
contains(value: T): boolean;
|
||||
include(value: T): boolean;
|
||||
invoke(methodName: string, ...args: any[]): any[];
|
||||
pluck(propertyName: string): any[];
|
||||
max(iterator?: Iterator<T, any>, context?: any): T;
|
||||
min(iterator?: Iterator<T, any>, context?: any): T;
|
||||
sortBy(iterator: Iterator<T, any>, context?: any): T[];
|
||||
sortBy(propertyName: string): T[];
|
||||
groupBy(iterator?: Iterator<T, any>, context?: any): Dictionary<T[]>;
|
||||
groupBy(propertyName: string): Dictionary<T[]>;
|
||||
countBy(iterator?: Iterator<T, any>, context?: any): Dictionary<number>;
|
||||
countBy(propertyName: string): Dictionary<number>;
|
||||
shuffle(): T[];
|
||||
toArray(): T[];
|
||||
size(): number;
|
||||
first(): T;
|
||||
first(count: number): T[];
|
||||
head(): T;
|
||||
head(count: number): T[];
|
||||
take(): T;
|
||||
take(count: number): T[];
|
||||
initial(): T;
|
||||
initial(count: number): T[];
|
||||
last(): T;
|
||||
last(count: number): T[];
|
||||
rest(index?: number): T[];
|
||||
compact(): T[];
|
||||
flatten<U>(shallow?: boolean): U[];
|
||||
without(...values: T[]): T[];
|
||||
union(...arrays: T[][]): T[];
|
||||
intersection(...arrays: T[][]): T[];
|
||||
difference(...others: T[][]): T[];
|
||||
uniq(isSorted?: boolean): T[];
|
||||
uniq<U>(isSorted: boolean, iterator: Iterator<T, U>, context?: any): U[];
|
||||
unique(isSorted?: boolean): T[];
|
||||
unique<U>(isSorted: boolean, iterator: Iterator<T, U>, context?: any): U[];
|
||||
zip(...arrays: any[][]): any[][];
|
||||
object(): any;
|
||||
object(values: any[]): any;
|
||||
indexOf(value: T, isSorted?: boolean): number;
|
||||
lastIndexOf(value: T, fromIndex?: number): number;
|
||||
sortedIndex(obj: T, propertyName: string): number;
|
||||
sortedIndex(obj: T, iterator?: Iterator<T, any>, context?: any): number;
|
||||
// Methods from Array
|
||||
concat(...items: T[]): T[];
|
||||
join(separator?: string): string;
|
||||
pop(): T;
|
||||
push(...items: T[]): number;
|
||||
reverse(): T[];
|
||||
shift(): T;
|
||||
slice(start: number, end?: number): T[];
|
||||
sort(compareFn?: (a: T, b: T) => number): T[];
|
||||
splice(start: number): T[];
|
||||
splice(start: number, deleteCount: number, ...items: T[]): T[];
|
||||
unshift(...items: T[]): number;
|
||||
}
|
||||
|
||||
export interface WrappedDictionary<T> extends WrappedObject<Dictionary<T>> {
|
||||
each(iterator: Iterator<T, void>, context?: any): void;
|
||||
forEach(iterator: Iterator<T, void>, context?: any): void;
|
||||
map<U>(iterator: Iterator<T, U>, context?: any): U[];
|
||||
collect<U>(iterator: Iterator<T, U>, context?: any): U[];
|
||||
reduce(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduce<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldl(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldl<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
inject(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
inject<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
reduceRight(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduceRight<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldr(iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldr<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
find(iterator: Iterator<T, boolean>, context?: any): T;
|
||||
detect(iterator: Iterator<T, boolean>, context?: any): T;
|
||||
filter(iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
select(iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
where(properties: Object): T[];
|
||||
findWhere(properties: Object): T;
|
||||
reject(iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
every(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
all(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
some(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
any(iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
contains(value: T): boolean;
|
||||
include(value: T): boolean;
|
||||
invoke(methodName: string, ...args: any[]): any[];
|
||||
pluck(propertyName: string): any[];
|
||||
max(iterator?: Iterator<T, any>, context?: any): T;
|
||||
min(iterator?: Iterator<T, any>, context?: any): T;
|
||||
sortBy(iterator: Iterator<T, any>, context?: any): T[];
|
||||
sortBy(propertyName: string): T[];
|
||||
groupBy(iterator?: Iterator<T, any>, context?: any): Dictionary<T[]>;
|
||||
groupBy(propertyName: string): Dictionary<T[]>;
|
||||
countBy(iterator?: Iterator<T, any>, context?: any): Dictionary<number>;
|
||||
countBy(propertyName: string): Dictionary<number>;
|
||||
shuffle(): T[];
|
||||
toArray(): T[];
|
||||
size(): number;
|
||||
}
|
||||
|
||||
export interface ChainedObject<T> {
|
||||
keys(): ChainedArray<string>;
|
||||
values(): ChainedArray<any>;
|
||||
pairs(): ChainedArray<any[]>;
|
||||
invert(): ChainedObject<any>;
|
||||
functions(): ChainedArray<string>;
|
||||
methods(): ChainedArray<string>;
|
||||
extend(...sources: any[]): ChainedObject<T>;
|
||||
pick(...keys: string[]): ChainedObject<T>;
|
||||
omit(...keys: string[]): ChainedObject<T>;
|
||||
defaults(...defaults: any[]): ChainedObject<T>;
|
||||
clone(): ChainedObject<T>;
|
||||
tap(interceptor: (object: T) => void): ChainedObject<T>;
|
||||
has(key: string): ChainedObject<boolean>;
|
||||
isEqual(other: T): ChainedObject<boolean>;
|
||||
isEmpty(): ChainedObject<boolean>;
|
||||
isElement(): ChainedObject<boolean>;
|
||||
isArray(): ChainedObject<boolean>;
|
||||
isObject(): ChainedObject<boolean>;
|
||||
isArguments(): ChainedObject<boolean>;
|
||||
isFunction(): ChainedObject<boolean>;
|
||||
isString(): ChainedObject<boolean>;
|
||||
isNumber(): ChainedObject<boolean>;
|
||||
isFinite(): ChainedObject<boolean>;
|
||||
isBoolean(): ChainedObject<boolean>;
|
||||
isDate(): ChainedObject<boolean>;
|
||||
isRegExp(): ChainedObject<boolean>;
|
||||
isNaN(): ChainedObject<boolean>;
|
||||
isNull(): ChainedObject<boolean>;
|
||||
isUndefined(): ChainedObject<boolean>;
|
||||
value(): T;
|
||||
}
|
||||
|
||||
export interface ChainedArray<T> extends ChainedObject<Array<T>> {
|
||||
each(iterator: Iterator<T, void>, context?: any): ChainedObject<void>;
|
||||
forEach(iterator: Iterator<T, void>, context?: any): ChainedObject<void>;
|
||||
map<U>(iterator: Iterator<T, U>, context?: any): ChainedArray<U>;
|
||||
collect<U>(iterator: Iterator<T, U>, context?: any): ChainedArray<U>;
|
||||
reduce(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
reduce<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
foldl(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
foldl<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
inject(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
inject<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
reduceRight(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
reduceRight<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
foldr(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
foldr<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
find(iterator: Iterator<T, boolean>, context?: any): ChainedObject<T>;
|
||||
detect(iterator: Iterator<T, boolean>, context?: any): ChainedObject<T>;
|
||||
filter(iterator: Iterator<T, boolean>, context?: any): ChainedArray<T>;
|
||||
select(iterator: Iterator<T, boolean>, context?: any): ChainedArray<T>;
|
||||
where(properties: Object): ChainedArray<T>;
|
||||
findWhere(properties: Object): ChainedObject<T>;
|
||||
reject(iterator: Iterator<T, boolean>, context?: any): ChainedArray<T>;
|
||||
every(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
all(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
some(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
any(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
contains(value: T): ChainedObject<boolean>;
|
||||
include(value: T): ChainedObject<boolean>;
|
||||
invoke(methodName: string, ...args: any[]): ChainedArray<any>;
|
||||
pluck(propertyName: string): ChainedArray<any>;
|
||||
max(iterator?: Iterator<T, any>, context?: any): ChainedObject<T>;
|
||||
min(iterator?: Iterator<T, any>, context?: any): ChainedObject<T>;
|
||||
sortBy(iterator: Iterator<T, any>, context?: any): ChainedArray<T>;
|
||||
sortBy(propertyName: string): ChainedArray<T>;
|
||||
// Should return ChainedDictionary<T[]>, but expansive recursion not allowed
|
||||
groupBy(iterator?: Iterator<T, any>, context?: any): ChainedDictionary<any[]>;
|
||||
groupBy(propertyName: string): ChainedDictionary<any[]>;
|
||||
countBy(iterator?: Iterator<T, any>, context?: any): ChainedDictionary<number>;
|
||||
countBy(propertyName: string): ChainedDictionary<number>;
|
||||
shuffle(): ChainedArray<T>;
|
||||
toArray(): ChainedArray<T>;
|
||||
size(): ChainedObject<number>;
|
||||
first(): ChainedObject<T>;
|
||||
first(count: number): ChainedArray<T>;
|
||||
head(): ChainedObject<T>;
|
||||
head(count: number): ChainedArray<T>;
|
||||
take(): ChainedObject<T>;
|
||||
take(count: number): ChainedArray<T>;
|
||||
initial(): ChainedObject<T>;
|
||||
initial(count: number): ChainedArray<T>;
|
||||
last(): ChainedObject<T>;
|
||||
last(count: number): ChainedArray<T>;
|
||||
rest(index?: number): ChainedArray<T>;
|
||||
compact(): ChainedArray<T>;
|
||||
flatten<U>(shallow?: boolean): ChainedArray<U>;
|
||||
without(...values: T[]): ChainedArray<T>;
|
||||
union(...arrays: T[][]): ChainedArray<T>;
|
||||
intersection(...arrays: T[][]): ChainedArray<T>;
|
||||
difference(...others: T[][]): ChainedArray<T>;
|
||||
uniq(isSorted?: boolean): ChainedArray<T>;
|
||||
uniq<U>(isSorted: boolean, iterator: Iterator<T, U>, context?: any): ChainedArray<U>;
|
||||
unique(isSorted?: boolean): ChainedArray<T>;
|
||||
unique<U>(isSorted: boolean, iterator: Iterator<T, U>, context?: any): ChainedArray<U>;
|
||||
zip(...arrays: any[][]): ChainedArray<any[]>;
|
||||
object(): ChainedObject<any>;
|
||||
object(values: any[]): ChainedObject<any>;
|
||||
indexOf(value: T, isSorted?: boolean): ChainedObject<number>;
|
||||
lastIndexOf(value: T, fromIndex?: number): ChainedObject<number>;
|
||||
sortedIndex(obj: T, propertyName: string): ChainedObject<number>;
|
||||
sortedIndex(obj: T, iterator?: Iterator<T, any>, context?: any): ChainedObject<number>;
|
||||
// Methods from Array
|
||||
concat(...items: T[]): ChainedArray<T>;
|
||||
join(separator?: string): ChainedObject<string>;
|
||||
pop(): ChainedObject<T>;
|
||||
push(...items: T[]): ChainedObject<number>;
|
||||
reverse(): ChainedArray<T>;
|
||||
shift(): ChainedObject<T>;
|
||||
slice(start: number, end?: number): ChainedArray<T>;
|
||||
sort(compareFn?: (a: T, b: T) => number): ChainedArray<T>;
|
||||
splice(start: number): ChainedArray<T>;
|
||||
splice(start: number, deleteCount: number, ...items: T[]): ChainedArray<T>;
|
||||
unshift(...items: T[]): ChainedObject<number>;
|
||||
// Methods from ChainedObject with promoted return types
|
||||
extend(...sources: any[]): ChainedArray<T>;
|
||||
pick(...keys: string[]): ChainedArray<T>;
|
||||
omit(...keys: string[]): ChainedArray<T>;
|
||||
defaults(...defaults: any[]): ChainedArray<T>;
|
||||
clone(): ChainedArray<T>;
|
||||
tap(interceptor: (object: T[]) => void): ChainedArray<T>;
|
||||
}
|
||||
|
||||
export interface ChainedDictionary<T> extends ChainedObject<Dictionary<T>> {
|
||||
each(iterator: Iterator<T, void>, context?: any): ChainedObject<void>;
|
||||
forEach(iterator: Iterator<T, void>, context?: any): ChainedObject<void>;
|
||||
map<U>(iterator: Iterator<T, U>, context?: any): ChainedArray<U>;
|
||||
collect<U>(iterator: Iterator<T, U>, context?: any): ChainedArray<U>;
|
||||
reduce(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
reduce<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
foldl(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
foldl<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
inject(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
inject<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
reduceRight(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
reduceRight<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
foldr(iterator: Reducer<T, T>, initialValue?: T, context?: any): ChainedObject<T>;
|
||||
foldr<U>(iterator: Reducer<T, U>, initialValue: U, context?: any): ChainedObject<U>;
|
||||
find(iterator: Iterator<T, boolean>, context?: any): ChainedObject<T>;
|
||||
detect(iterator: Iterator<T, boolean>, context?: any): ChainedObject<T>;
|
||||
filter(iterator: Iterator<T, boolean>, context?: any): ChainedArray<T>;
|
||||
select(iterator: Iterator<T, boolean>, context?: any): ChainedArray<T>;
|
||||
where(properties: Object): ChainedArray<T>;
|
||||
findWhere(properties: Object): ChainedObject<T>;
|
||||
reject(iterator: Iterator<T, boolean>, context?: any): ChainedArray<T>;
|
||||
every(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
all(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
some(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
any(iterator?: Iterator<T, boolean>, context?: any): ChainedObject<boolean>;
|
||||
contains(value: T): ChainedObject<boolean>;
|
||||
include(value: T): ChainedObject<boolean>;
|
||||
invoke(methodName: string, ...args: any[]): ChainedArray<any>;
|
||||
pluck(propertyName: string): ChainedArray<any>;
|
||||
max(iterator?: Iterator<T, any>, context?: any): ChainedObject<T>;
|
||||
min(iterator?: Iterator<T, any>, context?: any): ChainedObject<T>;
|
||||
sortBy(iterator: Iterator<T, any>, context?: any): ChainedArray<T>;
|
||||
sortBy(propertyName: string): ChainedArray<T>;
|
||||
// Should return ChainedDictionary<T[]>, but expansive recursion not allowed
|
||||
groupBy(iterator?: Iterator<T, any>, context?: any): ChainedDictionary<any[]>;
|
||||
groupBy(propertyName: string): ChainedDictionary<any[]>;
|
||||
countBy(iterator?: Iterator<T, any>, context?: any): ChainedDictionary<number>;
|
||||
countBy(propertyName: string): ChainedDictionary<number>;
|
||||
shuffle(): ChainedArray<T>;
|
||||
toArray(): ChainedArray<T>;
|
||||
size(): ChainedObject<number>;
|
||||
// Methods from ChainedObject with promoted return types
|
||||
extend(...sources: any[]): ChainedDictionary<T>;
|
||||
pick(...keys: string[]): ChainedDictionary<T>;
|
||||
omit(...keys: string[]): ChainedDictionary<T>;
|
||||
defaults(...defaults: any[]): ChainedDictionary<T>;
|
||||
clone(): ChainedDictionary<T>;
|
||||
tap(interceptor: (object: Dictionary<T>) => void): ChainedDictionary<T>;
|
||||
}
|
||||
|
||||
export interface TemplateSettings {
|
||||
evaluate?: RegExp;
|
||||
interpolate?: RegExp;
|
||||
escape?: RegExp;
|
||||
}
|
||||
|
||||
export interface Static {
|
||||
<T>(list: T[]): WrappedArray<T>;
|
||||
<T>(list: Dictionary<T>): WrappedDictionary<T>;
|
||||
<T extends Function>(func: T): WrappedFunction<T>;
|
||||
<T>(obj: T): WrappedObject<T>;
|
||||
|
||||
chain<T>(list: T[]): ChainedArray<T>;
|
||||
chain<T>(list: Dictionary<T>): ChainedDictionary<T>;
|
||||
chain<T>(obj: T): ChainedObject<T>;
|
||||
|
||||
each<T>(list: T[], iterator: Iterator<T, void>, context?: any): void;
|
||||
each<T>(list: Dictionary<T>, iterator: Iterator<T, void>, context?: any): void;
|
||||
forEach<T>(list: T[], iterator: Iterator<T, void>, context?: any): void;
|
||||
forEach<T>(list: Dictionary<T>, iterator: Iterator<T, void>, context?: any): void;
|
||||
|
||||
map<T, U>(list: T[], iterator: Iterator<T, U>, context?: any): U[];
|
||||
map<T, U>(list: Dictionary<T>, iterator: Iterator<T, U>, context?: any): U[];
|
||||
collect<T, U>(list: T[], iterator: Iterator<T, U>, context?: any): U[];
|
||||
collect<T, U>(list: Dictionary<T>, iterator: Iterator<T, U>, context?: any): U[];
|
||||
|
||||
reduce<T>(list: T[], iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduce<T, U>(list: T[], iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
reduce<T>(list: Dictionary<T>, iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduce<T, U>(list: Dictionary<T>, iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldl<T>(list: T[], iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldl<T, U>(list: T[], iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldl<T>(list: Dictionary<T>, iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldl<T, U>(list: Dictionary<T>, iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
inject<T>(list: T[], iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
inject<T, U>(list: T[], iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
inject<T>(list: Dictionary<T>, iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
inject<T, U>(list: Dictionary<T>, iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
|
||||
reduceRight<T>(list: T[], iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduceRight<T, U>(list: T[], iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
reduceRight<T>(list: Dictionary<T>, iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
reduceRight<T, U>(list: Dictionary<T>, iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldr<T>(list: T[], iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldr<T, U>(list: T[], iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
foldr<T>(list: Dictionary<T>, iterator: Reducer<T, T>, initialValue?: T, context?: any): T;
|
||||
foldr<T, U>(list: Dictionary<T>, iterator: Reducer<T, U>, initialValue: U, context?: any): U;
|
||||
|
||||
find<T>(list: T[], iterator: Iterator<T, boolean>, context?: any): T;
|
||||
find<T>(list: Dictionary<T>, iterator: Iterator<T, boolean>, context?: any): T;
|
||||
detect<T>(list: T[], iterator: Iterator<T, boolean>, context?: any): T;
|
||||
detect<T>(list: Dictionary<T>, iterator: Iterator<T, boolean>, context?: any): T;
|
||||
|
||||
filter<T>(list: T[], iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
filter<T>(list: Dictionary<T>, iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
select<T>(list: T[], iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
select<T>(list: Dictionary<T>, iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
|
||||
where<T>(list: T[], properties: Object): T[];
|
||||
where<T>(list: Dictionary<T>, properties: Object): T[];
|
||||
|
||||
findWhere<T>(list: T[], properties: Object): T;
|
||||
findWhere<T>(list: Dictionary<T>, properties: Object): T;
|
||||
|
||||
reject<T>(list: T[], iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
reject<T>(list: Dictionary<T>, iterator: Iterator<T, boolean>, context?: any): T[];
|
||||
|
||||
every<T>(list: T[], iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
every<T>(list: Dictionary<T>, iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
all<T>(list: T[], iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
all<T>(list: Dictionary<T>, iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
|
||||
some<T>(list: T[], iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
some<T>(list: Dictionary<T>, iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
any<T>(list: T[], iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
any<T>(list: Dictionary<T>, iterator?: Iterator<T, boolean>, context?: any): boolean;
|
||||
|
||||
contains<T>(list: T[], value: T): boolean;
|
||||
contains<T>(list: Dictionary<T>, value: T): boolean;
|
||||
include<T>(list: T[], value: T): boolean;
|
||||
include<T>(list: Dictionary<T>, value: T): boolean;
|
||||
|
||||
invoke(list: any[], methodName: string, ...args: any[]): any[];
|
||||
invoke(list: Dictionary<any>, methodName: string, ...args: any[]): any[];
|
||||
|
||||
pluck(list: any[], propertyName: string): any[];
|
||||
pluck(list: Dictionary<any>, propertyName: string): any[];
|
||||
|
||||
max<T>(list: T[], iterator?: Iterator<T, any>, context?: any): T;
|
||||
max<T>(list: Dictionary<T>, iterator?: Iterator<T, any>, context?: any): T;
|
||||
|
||||
min<T>(list: T[], iterator?: Iterator<T, any>, context?: any): T;
|
||||
min<T>(list: Dictionary<T>, iterator?: Iterator<T, any>, context?: any): T;
|
||||
|
||||
sortBy<T>(list: T[], iterator: Iterator<T, any>, context?: any): T[];
|
||||
sortBy<T>(list: Dictionary<T>, iterator: Iterator<T, any>, context?: any): T[];
|
||||
sortBy<T>(list: T[], propertyName: string): T[];
|
||||
sortBy<T>(list: Dictionary<T>, propertyName: string): T[];
|
||||
|
||||
groupBy<T>(list: T[], iterator?: Iterator<T, any>, context?: any): Dictionary<T[]>;
|
||||
groupBy<T>(list: Dictionary<T>, iterator?: Iterator<T, any>, context?: any): Dictionary<T[]>;
|
||||
groupBy<T>(list: T[], propertyName: string): Dictionary<T[]>;
|
||||
groupBy<T>(list: Dictionary<T>, propertyName: string): Dictionary<T[]>;
|
||||
|
||||
countBy<T>(list: T[], iterator?: Iterator<T, any>, context?: any): Dictionary<number>;
|
||||
countBy<T>(list: Dictionary<T>, iterator?: Iterator<T, any>, context?: any): Dictionary<number>;
|
||||
countBy<T>(list: T[], propertyName: string): Dictionary<number>;
|
||||
countBy<T>(list: Dictionary<T>, propertyName: string): Dictionary<number>;
|
||||
|
||||
shuffle<T>(list: T[]): T[];
|
||||
shuffle<T>(list: Dictionary<T>): T[];
|
||||
|
||||
toArray<T>(list: T[]): T[];
|
||||
toArray<T>(list: Dictionary<T>): T[];
|
||||
|
||||
size<T>(list: T[]): number;
|
||||
size<T>(list: Dictionary<T>): number;
|
||||
|
||||
first<T>(list: T[]): T;
|
||||
first<T>(list: T[], count: number): T[];
|
||||
head<T>(list: T[]): T;
|
||||
head<T>(list: T[], count: number): T[];
|
||||
take<T>(list: T[]): T;
|
||||
take<T>(list: T[], count: number): T[];
|
||||
|
||||
initial<T>(list: T[]): T;
|
||||
initial<T>(list: T[], count: number): T[];
|
||||
|
||||
last<T>(list: T[]): T;
|
||||
last<T>(list: T[], count: number): T[];
|
||||
|
||||
rest<T>(list: T[], index?: number): T[];
|
||||
|
||||
compact<T>(list: T[]): T[];
|
||||
|
||||
flatten<T>(list: T[][]): T[];
|
||||
flatten<T>(array: any[], shallow?: boolean): T[];
|
||||
|
||||
without<T>(list: T[], ...values: T[]): T[];
|
||||
|
||||
union<T>(...arrays: T[][]): T[];
|
||||
|
||||
intersection<T>(...arrays: T[][]): T[];
|
||||
|
||||
difference<T>(list: T[], ...others: T[][]): T[];
|
||||
|
||||
uniq<T>(list: T[], isSorted?: boolean): T[];
|
||||
uniq<T, U>(list: T[], isSorted: boolean, iterator: Iterator<T, U>, context?: any): U[];
|
||||
unique<T>(list: T[], isSorted?: boolean): T[];
|
||||
unique<T, U>(list: T[], isSorted: boolean, iterator: Iterator<T, U>, context?: any): U[];
|
||||
|
||||
zip<T0, T1>(a0: T0[], a1: T1[]): Tuple2<T0, T1>[];
|
||||
zip<T0, T1, T2>(a0: T0[], a1: T1[], a2: T2[]): Tuple3<T0, T1, T2>[];
|
||||
zip<T0, T1, T2, T3>(a0: T0[], a1: T1[], a2: T2[], a3: T3[]): Tuple4<T0, T1, T2, T3>[];
|
||||
zip(...arrays: any[][]): any[][];
|
||||
|
||||
object(list: any[][]): any;
|
||||
object(keys: string[], values: any[]): any;
|
||||
|
||||
indexOf<T>(list: T[], value: T, isSorted?: boolean): number;
|
||||
|
||||
lastIndexOf<T>(list: T[], value: T, fromIndex?: number): number;
|
||||
|
||||
sortedIndex<T>(list: T[], obj: T, propertyName: string): number;
|
||||
sortedIndex<T>(list: T[], obj: T, iterator?: Iterator<T, any>, context?: any): number;
|
||||
|
||||
range(stop: number): number[];
|
||||
range(start: number, stop: number, step?: number): number[];
|
||||
|
||||
bind<T extends Function>(func: T, object: any): T;
|
||||
bind(func: Function, object: any, ...args: any[]): Function;
|
||||
|
||||
bindAll<T>(object: T, ...methodNames: string[]): T;
|
||||
|
||||
partial(func: Function, ...args: any[]): Function;
|
||||
|
||||
memoize<T extends Function>(func: T, hashFunction?: Function): T;
|
||||
|
||||
delay(func: Function, wait: number, ...args: any[]): number;
|
||||
|
||||
defer(func: Function, ...args: any[]): number;
|
||||
|
||||
throttle<T extends Function>(func: T, wait: number): T;
|
||||
|
||||
debounce<T extends Function>(func: T, wait: number, immediate?: boolean): T;
|
||||
|
||||
once<T extends Function>(func: T): T;
|
||||
|
||||
after<T extends Function>(count: number, func: T): T;
|
||||
|
||||
wrap<T extends Function>(func: T, wrapper: (func: T, ...args: any[]) => any): T;
|
||||
|
||||
compose(...funcs: Function[]): Function;
|
||||
|
||||
keys(object: any): string[];
|
||||
|
||||
values(object: any): any[];
|
||||
|
||||
pairs(object: any): any[][];
|
||||
|
||||
invert(object: any): any;
|
||||
|
||||
functions(object: any): string[];
|
||||
methods(object: any): string[];
|
||||
|
||||
extend<T>(destination: T, ...sources: any[]): T;
|
||||
|
||||
pick<T>(object: T, ...keys: string[]): T;
|
||||
|
||||
omit<T>(object: T, ...keys: string[]): T;
|
||||
|
||||
defaults<T>(object: T, ...defaults: any[]): T;
|
||||
|
||||
clone<T>(object: T): T;
|
||||
|
||||
tap<T>(object: T, interceptor: (object: T) => void): T;
|
||||
|
||||
has(object: any, key: string): boolean;
|
||||
|
||||
isEqual<T>(object: T, other: T): boolean;
|
||||
|
||||
isEmpty(object: any): boolean;
|
||||
isElement(object: any): boolean;
|
||||
isArray(object: any): boolean;
|
||||
isObject(value: any): boolean;
|
||||
isArguments(object: any): boolean;
|
||||
isFunction(object: any): boolean;
|
||||
isString(object: any): boolean;
|
||||
isNumber(object: any): boolean;
|
||||
isFinite(object: any): boolean;
|
||||
isBoolean(object: any): boolean;
|
||||
isDate(object: any): boolean;
|
||||
isRegExp(object: any): boolean;
|
||||
isNaN(object: any): boolean;
|
||||
isNull(object: any): boolean;
|
||||
isUndefined(value: any): boolean;
|
||||
|
||||
noConflict(): Static;
|
||||
|
||||
identity<T>(value: T): T;
|
||||
|
||||
times<U>(n: number, iterator: Iterator<number, U>, context?: any): U[];
|
||||
|
||||
random(max: number): number;
|
||||
random(min: number, max: number): number;
|
||||
|
||||
mixin(object: any): void;
|
||||
|
||||
uniqueId(): number;
|
||||
uniqueId(prefix: string): string;
|
||||
|
||||
escape(s: string): string;
|
||||
|
||||
unescape(s: string): string;
|
||||
|
||||
result(object: any, property: string): any;
|
||||
|
||||
templateSettings: TemplateSettings;
|
||||
|
||||
template(templateString: string): (data: any) => string;
|
||||
template(templateString: string, data: any, settings?: TemplateSettings): string;
|
||||
}
|
||||
}
|
||||
|
||||
declare var _: Underscore.Static;
|
||||
|
||||
41
tests/baselines/reference/weakType.errors.txt
Normal file
41
tests/baselines/reference/weakType.errors.txt
Normal file
@ -0,0 +1,41 @@
|
||||
tests/cases/compiler/weakType.ts(31,18): error TS2345: Argument of type '{ error?: number; }' is not assignable to parameter of type 'ChangeOptions'.
|
||||
Weak type 'ChangeOptions' has no properties in common with '{ error?: number; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/weakType.ts (1 errors) ====
|
||||
interface Settings {
|
||||
timeout?: number;
|
||||
onError?(): void;
|
||||
}
|
||||
|
||||
function getDefaultSettings() {
|
||||
return { timeout: 1000 };
|
||||
}
|
||||
|
||||
function doSomething(settings: Settings) { /* ... */ }
|
||||
|
||||
// forgot to call `getDefaultSettings`
|
||||
// but it is not caught because we don't check for call signatures
|
||||
doSomething(getDefaultSettings);
|
||||
|
||||
// this is an oddly popular way of defining settings
|
||||
// this example is from services/textChanges.ts
|
||||
type ConfigurableStart = { useStart?: boolean }
|
||||
type ConfigurableEnd = { useEnd?: boolean }
|
||||
type ConfigurableStartEnd = ConfigurableStart & ConfigurableEnd
|
||||
interface InsertOptions {
|
||||
prefix?: string
|
||||
suffix?: string
|
||||
}
|
||||
type ChangeOptions = ConfigurableStartEnd & InsertOptions;
|
||||
|
||||
function del(options: ConfigurableStartEnd = {},
|
||||
error: { error?: number } = {}) {
|
||||
let changes: ChangeOptions[];
|
||||
changes.push(options);
|
||||
changes.push(error);
|
||||
~~~~~
|
||||
!!! error TS2345: Argument of type '{ error?: number; }' is not assignable to parameter of type 'ChangeOptions'.
|
||||
!!! error TS2345: Weak type 'ChangeOptions' has no properties in common with '{ error?: number; }'.
|
||||
}
|
||||
|
||||
@ -10,7 +10,27 @@ function getDefaultSettings() {
|
||||
|
||||
function doSomething(settings: Settings) { /* ... */ }
|
||||
|
||||
// forgot to call `getDefaultSettings`
|
||||
// but it is not caught because we don't check for call signatures
|
||||
doSomething(getDefaultSettings);
|
||||
|
||||
// this is an oddly popular way of defining settings
|
||||
// this example is from services/textChanges.ts
|
||||
type ConfigurableStart = { useStart?: boolean }
|
||||
type ConfigurableEnd = { useEnd?: boolean }
|
||||
type ConfigurableStartEnd = ConfigurableStart & ConfigurableEnd
|
||||
interface InsertOptions {
|
||||
prefix?: string
|
||||
suffix?: string
|
||||
}
|
||||
type ChangeOptions = ConfigurableStartEnd & InsertOptions;
|
||||
|
||||
function del(options: ConfigurableStartEnd = {},
|
||||
error: { error?: number } = {}) {
|
||||
let changes: ChangeOptions[];
|
||||
changes.push(options);
|
||||
changes.push(error);
|
||||
}
|
||||
|
||||
|
||||
//// [weakType.js]
|
||||
@ -18,4 +38,13 @@ function getDefaultSettings() {
|
||||
return { timeout: 1000 };
|
||||
}
|
||||
function doSomething(settings) { }
|
||||
// forgot to call `getDefaultSettings`
|
||||
// but it is not caught because we don't check for call signatures
|
||||
doSomething(getDefaultSettings);
|
||||
function del(options, error) {
|
||||
if (options === void 0) { options = {}; }
|
||||
if (error === void 0) { error = {}; }
|
||||
var changes;
|
||||
changes.push(options);
|
||||
changes.push(error);
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
=== tests/cases/compiler/weakType.ts ===
|
||||
interface Settings {
|
||||
>Settings : Symbol(Settings, Decl(weakType.ts, 0, 0))
|
||||
|
||||
timeout?: number;
|
||||
>timeout : Symbol(timeout, Decl(weakType.ts, 0, 20))
|
||||
|
||||
onError?(): void;
|
||||
>onError : Symbol(onError, Decl(weakType.ts, 1, 21))
|
||||
}
|
||||
|
||||
function getDefaultSettings() {
|
||||
>getDefaultSettings : Symbol(getDefaultSettings, Decl(weakType.ts, 3, 1))
|
||||
|
||||
return { timeout: 1000 };
|
||||
>timeout : Symbol(timeout, Decl(weakType.ts, 6, 12))
|
||||
}
|
||||
|
||||
function doSomething(settings: Settings) { /* ... */ }
|
||||
>doSomething : Symbol(doSomething, Decl(weakType.ts, 7, 1))
|
||||
>settings : Symbol(settings, Decl(weakType.ts, 9, 21))
|
||||
>Settings : Symbol(Settings, Decl(weakType.ts, 0, 0))
|
||||
|
||||
doSomething(getDefaultSettings);
|
||||
>doSomething : Symbol(doSomething, Decl(weakType.ts, 7, 1))
|
||||
>getDefaultSettings : Symbol(getDefaultSettings, Decl(weakType.ts, 3, 1))
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
=== tests/cases/compiler/weakType.ts ===
|
||||
interface Settings {
|
||||
>Settings : Settings
|
||||
|
||||
timeout?: number;
|
||||
>timeout : number
|
||||
|
||||
onError?(): void;
|
||||
>onError : () => void
|
||||
}
|
||||
|
||||
function getDefaultSettings() {
|
||||
>getDefaultSettings : () => { timeout: number; }
|
||||
|
||||
return { timeout: 1000 };
|
||||
>{ timeout: 1000 } : { timeout: number; }
|
||||
>timeout : number
|
||||
>1000 : number
|
||||
}
|
||||
|
||||
function doSomething(settings: Settings) { /* ... */ }
|
||||
>doSomething : (settings: Settings) => void
|
||||
>settings : Settings
|
||||
>Settings : Settings
|
||||
|
||||
doSomething(getDefaultSettings);
|
||||
>doSomething(getDefaultSettings) : void
|
||||
>doSomething : (settings: Settings) => void
|
||||
>getDefaultSettings : () => { timeout: number; }
|
||||
|
||||
@ -15,7 +15,7 @@ declare var fs: {
|
||||
existsSync(path: string): boolean;
|
||||
readdirSync(path: string): string[];
|
||||
readFileSync(filename: string, encoding?: string): string;
|
||||
writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void;
|
||||
writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; } | string): void;
|
||||
watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: { mtime: Date }, prev: { mtime: Date }) => void): void;
|
||||
};
|
||||
declare var path: any;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user