feat(build): require parameter types

Fixes #2833
This commit is contained in:
Alex Eagle
2015-07-07 20:03:00 -07:00
parent 6d760666a9
commit de18da2a0d
81 changed files with 379 additions and 290 deletions
@@ -207,7 +207,7 @@ export function main() {
let l = [NumberWrapper.NaN, NumberWrapper.NaN];
changes.check(l);
ListWrapper.insert(l, 0, 'foo');
ListWrapper.insert<any>(l, 0, 'foo');
changes.check(l);
expect(changes.toString())
.toEqual(iterableChangesAsString({
@@ -76,8 +76,10 @@ export function main() {
describe("createDirectiveVariableBindings", () => {
it("should calculate directive variable bindings", () => {
var dvbs = createDirectiveVariableBindings(
new renderApi.ElementBinder(
{variableBindings: MapWrapper.createFromStringMap({"exportName": "templateName"})}),
new renderApi.ElementBinder({
variableBindings:
MapWrapper.createFromStringMap<string>({"exportName": "templateName"})
}),
[
directiveBinding(
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'exportName'})}),
@@ -85,13 +87,15 @@ export function main() {
{metadata: renderApi.DirectiveMetadata.create({exportAs: 'otherName'})})
]);
expect(dvbs).toEqual(MapWrapper.createFromStringMap({"templateName": 0}));
expect(dvbs).toEqual(MapWrapper.createFromStringMap<number>({"templateName": 0}));
});
it("should set exportAs to $implicit for component with exportAs = null", () => {
var dvbs = createDirectiveVariableBindings(
new renderApi.ElementBinder(
{variableBindings: MapWrapper.createFromStringMap({"$implicit": "templateName"})}),
new renderApi.ElementBinder({
variableBindings:
MapWrapper.createFromStringMap<string>({"$implicit": "templateName"})
}),
[
directiveBinding({
metadata: renderApi.DirectiveMetadata.create(
@@ -99,7 +103,7 @@ export function main() {
})
]);
expect(dvbs).toEqual(MapWrapper.createFromStringMap({"templateName": 0}));
expect(dvbs).toEqual(MapWrapper.createFromStringMap<number>({"templateName": 0}));
});
it("should throw we no directive exported with this name", () => {
@@ -107,7 +111,7 @@ export function main() {
createDirectiveVariableBindings(
new renderApi.ElementBinder({
variableBindings:
MapWrapper.createFromStringMap({"someInvalidName": "templateName"})
MapWrapper.createFromStringMap<string>({"someInvalidName": "templateName"})
}),
[
directiveBinding(
@@ -120,7 +124,8 @@ export function main() {
expect(() => {
createDirectiveVariableBindings(
new renderApi.ElementBinder({
variableBindings: MapWrapper.createFromStringMap({"exportName": "templateName"})
variableBindings:
MapWrapper.createFromStringMap<string>({"exportName": "templateName"})
}),
[
directiveBinding(
@@ -148,11 +153,11 @@ export function main() {
it('should merge the names in the template for all ElementBinders', () => {
expect(createVariableLocations([
new renderApi.ElementBinder(
{variableBindings: MapWrapper.createFromStringMap({"x": "a"})}),
{variableBindings: MapWrapper.createFromStringMap<string>({"x": "a"})}),
new renderApi.ElementBinder(
{variableBindings: MapWrapper.createFromStringMap({"y": "b"})})
{variableBindings: MapWrapper.createFromStringMap<string>({"y": "b"})})
])).toEqual(MapWrapper.createFromStringMap({'a': 0, 'b': 1}));
])).toEqual(MapWrapper.createFromStringMap<number>({'a': 0, 'b': 1}));
});
});
});
+1 -1
View File
@@ -206,7 +206,7 @@ export function main() {
var injector = createInjector([
bind('originalEngine')
.toClass(forwardRef(() => Engine)),
bind('aliasedEngine').toAlias(forwardRef(() => 'originalEngine'))
bind('aliasedEngine').toAlias(<any>forwardRef(() => 'originalEngine'))
]);
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
});
@@ -18,6 +18,7 @@ import {bind, Injector} from 'angular2/di';
import {isPresent, StringWrapper} from 'angular2/src/facade/lang';
import {TimerWrapper} from 'angular2/src/facade/async';
import {Request} from 'angular2/src/http/static_request';
import {Response} from 'angular2/src/http/static_response';
import {Map} from 'angular2/src/facade/collection';
import {RequestOptions, BaseRequestOptions} from 'angular2/src/http/base_request_options';
import {BaseResponseOptions, ResponseOptions} from 'angular2/src/http/base_response_options';
@@ -25,6 +26,7 @@ import {ResponseTypes, ReadyStates, RequestMethods} from 'angular2/src/http/enum
var addEventListenerSpy;
var existingScripts = [];
var unused: Response;
class MockBrowserJsonp extends BrowserJsonp {
src: string;
@@ -87,7 +89,7 @@ export function main() {
inject([AsyncTestCompleter], async => {
let connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp(),
new ResponseOptions({type: ResponseTypes.Error}));
ObservableWrapper.subscribe(connection.response, res => {
ObservableWrapper.subscribe<Response>(connection.response, res => {
expect(res.type).toBe(ResponseTypes.Error);
async.done();
});
@@ -164,7 +166,7 @@ export function main() {
it('should respond with data passed to callback', inject([AsyncTestCompleter], async => {
let connection = new JSONPConnection(sampleRequest, new MockBrowserJsonp());
ObservableWrapper.subscribe(connection.response, res => {
ObservableWrapper.subscribe<Response>(connection.response, res => {
expect(res.json()).toEqual(({fake_payload: true, blob_id: 12345}));
async.done();
});
@@ -16,6 +16,7 @@ import {BrowserXhr} from 'angular2/src/http/backends/browser_xhr';
import {XHRConnection, XHRBackend} from 'angular2/src/http/backends/xhr_backend';
import {bind, Injector} from 'angular2/di';
import {Request} from 'angular2/src/http/static_request';
import {Response} from 'angular2/src/http/static_response';
import {Headers} from 'angular2/src/http/headers';
import {Map} from 'angular2/src/facade/collection';
import {RequestOptions, BaseRequestOptions} from 'angular2/src/http/base_request_options';
@@ -28,6 +29,7 @@ var openSpy;
var setRequestHeaderSpy;
var addEventListenerSpy;
var existingXHRs = [];
var unused: Response;
class MockBrowserXHR extends BrowserXhr {
abort: any;
@@ -86,7 +88,7 @@ export function main() {
inject([AsyncTestCompleter], async => {
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
new ResponseOptions({type: ResponseTypes.Error}));
ObservableWrapper.subscribe(connection.response, res => {
ObservableWrapper.subscribe<Response>(connection.response, res => {
expect(res.type).toBe(ResponseTypes.Error);
async.done();
});
+14 -13
View File
@@ -13,7 +13,7 @@ import {
} from 'angular2/test_lib';
import {Http} from 'angular2/src/http/http';
import {Injector, bind} from 'angular2/di';
import {MockBackend} from 'angular2/src/http/backends/mock_backend';
import {MockBackend, MockConnection} from 'angular2/src/http/backends/mock_backend';
import {Response} from 'angular2/src/http/static_response';
import {RequestMethods} from 'angular2/src/http/enums';
import {BaseRequestOptions, RequestOptions} from 'angular2/src/http/base_request_options';
@@ -66,7 +66,7 @@ export function main() {
it('should accept a fully-qualified request as its only parameter',
inject([AsyncTestCompleter], (async) => {
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.url).toBe('https://google.com');
c.mockRespond(new Response(new ResponseOptions({body: 'Thank you'})));
async.done();
@@ -79,8 +79,9 @@ export function main() {
it('should perform a get request for given url if only passed a string',
inject([AsyncTestCompleter], (async) => {
ObservableWrapper.subscribe(backend.connections, c => c.mockRespond(baseResponse));
ObservableWrapper.subscribe(http.request('http://basic.connection'), res => {
ObservableWrapper.subscribe<MockConnection>(backend.connections,
c => c.mockRespond(baseResponse));
ObservableWrapper.subscribe<Response>(http.request('http://basic.connection'), res => {
expect(res.text()).toBe('base response');
async.done();
});
@@ -102,7 +103,7 @@ export function main() {
describe('.get()', () => {
it('should perform a get request for given url', inject([AsyncTestCompleter], async => {
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.method).toBe(RequestMethods.GET);
backend.resolveAllConnections();
async.done();
@@ -114,7 +115,7 @@ export function main() {
describe('.post()', () => {
it('should perform a post request for given url', inject([AsyncTestCompleter], async => {
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.method).toBe(RequestMethods.POST);
backend.resolveAllConnections();
async.done();
@@ -125,7 +126,7 @@ export function main() {
it('should attach the provided body to the request', inject([AsyncTestCompleter], async => {
var body = 'this is my post body';
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.text()).toBe(body);
backend.resolveAllConnections();
async.done();
@@ -137,7 +138,7 @@ export function main() {
describe('.put()', () => {
it('should perform a put request for given url', inject([AsyncTestCompleter], async => {
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.method).toBe(RequestMethods.PUT);
backend.resolveAllConnections();
async.done();
@@ -147,7 +148,7 @@ export function main() {
it('should attach the provided body to the request', inject([AsyncTestCompleter], async => {
var body = 'this is my put body';
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.text()).toBe(body);
backend.resolveAllConnections();
async.done();
@@ -159,7 +160,7 @@ export function main() {
describe('.delete()', () => {
it('should perform a delete request for given url', inject([AsyncTestCompleter], async => {
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.method).toBe(RequestMethods.DELETE);
backend.resolveAllConnections();
async.done();
@@ -171,7 +172,7 @@ export function main() {
describe('.patch()', () => {
it('should perform a patch request for given url', inject([AsyncTestCompleter], async => {
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.method).toBe(RequestMethods.PATCH);
backend.resolveAllConnections();
async.done();
@@ -181,7 +182,7 @@ export function main() {
it('should attach the provided body to the request', inject([AsyncTestCompleter], async => {
var body = 'this is my patch body';
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.text()).toBe(body);
backend.resolveAllConnections();
async.done();
@@ -193,7 +194,7 @@ export function main() {
describe('.head()', () => {
it('should perform a head request for given url', inject([AsyncTestCompleter], async => {
ObservableWrapper.subscribe(backend.connections, c => {
ObservableWrapper.subscribe<MockConnection>(backend.connections, c => {
expect(c.request.method).toBe(RequestMethods.HEAD);
backend.resolveAllConnections();
async.done();
@@ -232,25 +232,27 @@ var someDirectiveWithProps = DirectiveMetadata.create({
var someDirectiveWithHostProperties = DirectiveMetadata.create({
selector: '[some-decor-with-host-props]',
host: MapWrapper.createFromStringMap({'[hostProp]': 'dirProp'})
host: MapWrapper.createFromStringMap<string>({'[hostProp]': 'dirProp'})
});
var someDirectiveWithInvalidHostProperties = DirectiveMetadata.create({
selector: '[some-decor-with-invalid-host-props]',
host: MapWrapper.createFromStringMap({'[hostProp]': 'dirProp + dirProp2'})
host: MapWrapper.createFromStringMap<string>({'[hostProp]': 'dirProp + dirProp2'})
});
var someDirectiveWithHostAttributes = DirectiveMetadata.create({
selector: '[some-decor-with-host-attrs]',
host: MapWrapper.createFromStringMap({'attr_name': 'attr_val', 'class': 'foo bar'})
host: MapWrapper.createFromStringMap<string>({'attr_name': 'attr_val', 'class': 'foo bar'})
});
var someDirectiveWithEvents = DirectiveMetadata.create(
{selector: '[some-decor-events]', host: MapWrapper.createFromStringMap({'(click)': 'doIt()'})});
var someDirectiveWithEvents = DirectiveMetadata.create({
selector: '[some-decor-events]',
host: MapWrapper.createFromStringMap<string>({'(click)': 'doIt()'})
});
var someDirectiveWithGlobalEvents = DirectiveMetadata.create({
selector: '[some-decor-globalevents]',
host: MapWrapper.createFromStringMap({'(window:resize)': 'doItGlobal()'})
host: MapWrapper.createFromStringMap<string>({'(window:resize)': 'doItGlobal()'})
});
var componentWithNonElementSelector = DirectiveMetadata.create({
+8 -8
View File
@@ -257,7 +257,7 @@ export function main() {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => {
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('parent activate')) {
completer.resolve(true);
}
@@ -292,7 +292,7 @@ export function main() {
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => rtr.navigate('/parent-deactivate/child-deactivate'))
.then((_) => {
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('deactivate')) {
completer.resolve(true);
rootTC.detectChanges();
@@ -356,7 +356,7 @@ export function main() {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => {
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('canActivate')) {
completer.resolve(true);
}
@@ -376,7 +376,7 @@ export function main() {
compile()
.then((_) => rtr.config([new Route({path: '/...', component: LifecycleCmp})]))
.then((_) => {
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('canActivate')) {
completer.resolve(false);
}
@@ -401,7 +401,7 @@ export function main() {
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual('');
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('canDeactivate')) {
completer.resolve(true);
}
@@ -426,7 +426,7 @@ export function main() {
expect(rootTC.nativeElement).toHaveText('canDeactivate {A}');
expect(log).toEqual('');
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('canDeactivate')) {
completer.resolve(false);
}
@@ -473,7 +473,7 @@ export function main() {
expect(log).toEqual('canActivate: null -> /reuse-hooks/1;' +
'onActivate: null -> /reuse-hooks/1;');
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('canReuse')) {
completer.resolve(true);
}
@@ -497,7 +497,7 @@ export function main() {
expect(log).toEqual('canActivate: null -> /reuse-hooks/1;' +
'onActivate: null -> /reuse-hooks/1;');
ObservableWrapper.subscribe(eventBus, (ev) => {
ObservableWrapper.subscribe<string>(eventBus, (ev) => {
if (ev.startsWith('canReuse')) {
completer.resolve(false);
}