mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(core): cleanup type any (#48623)
Removing every type any in core with a reference to #9100 PR Close #48623
This commit is contained in:
committed by
Alex Rickabaugh
parent
4621be3081
commit
10c10ee559
@@ -1524,7 +1524,7 @@ export enum ViewEncapsulation {
|
||||
export abstract class ViewRef extends ChangeDetectorRef {
|
||||
abstract destroy(): void;
|
||||
abstract get destroyed(): boolean;
|
||||
abstract onDestroy(callback: Function): any /** TODO #9100 */;
|
||||
abstract onDestroy(callback: Function): any /** TODO #9100, replace by void in a major release*/;
|
||||
}
|
||||
|
||||
// @public
|
||||
|
||||
@@ -33,7 +33,7 @@ export abstract class ViewRef extends ChangeDetectorRef {
|
||||
* @param callback A handler function that cleans up developer-defined data
|
||||
* associated with a view. Called when the `destroy()` method is invoked.
|
||||
*/
|
||||
abstract onDestroy(callback: Function): any /** TODO #9100 */;
|
||||
abstract onDestroy(callback: Function): any /** TODO #9100, replace by void in a major release*/;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
*/
|
||||
|
||||
// TODO(jteplitz602): Load WorkerGlobalScope from lib.webworker.d.ts file #3492
|
||||
declare var WorkerGlobalScope: any /** TODO #9100 */;
|
||||
declare var WorkerGlobalScope: any;
|
||||
// CommonJS / Node have global context exposed as "global" variable.
|
||||
// We don't want to include the whole node.d.ts this this compilation unit so we'll just fake
|
||||
// the global "global" var for now.
|
||||
declare var global: any /** TODO #9100 */;
|
||||
declare var global: any;
|
||||
|
||||
// Always use __globalThis if available, which is the spec-defined global variable across all
|
||||
// environments, then fallback to __global first, because in Node tests both __global and
|
||||
|
||||
@@ -493,11 +493,9 @@ describe('resolve', () => {
|
||||
});
|
||||
|
||||
it('should support overriding factory dependencies with dependency annotations', () => {
|
||||
const providers = ReflectiveInjector.resolve([{
|
||||
provide: 'token',
|
||||
useFactory: (e: any /** TODO #9100 */) => 'result',
|
||||
deps: [[new Inject('dep')]]
|
||||
}]);
|
||||
const providers = ReflectiveInjector.resolve([
|
||||
{provide: 'token', useFactory: () => 'result', deps: [[new Inject('dep')]]},
|
||||
]);
|
||||
|
||||
const provider = providers[0];
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ class LifecycleDir implements DoCheck {
|
||||
})
|
||||
class LifecycleCmp implements OnChanges, OnInit, DoCheck, AfterContentInit, AfterContentChecked,
|
||||
AfterViewInit, AfterViewChecked {
|
||||
field: any /** TODO #9100 */;
|
||||
field: number = 0;
|
||||
constructor(private _log: Log) {}
|
||||
|
||||
ngOnChanges(_: any /** TODO #9100 */) {
|
||||
ngOnChanges() {
|
||||
this._log.add('ngOnChanges');
|
||||
}
|
||||
|
||||
|
||||
@@ -13,15 +13,15 @@ import '@angular/core/testing';
|
||||
{
|
||||
describe('Shim', () => {
|
||||
it('should provide correct function.name ', () => {
|
||||
const functionWithoutName = identity(() => function(_: any /** TODO #9100 */) {});
|
||||
function foo(_: any /** TODO #9100 */) {}
|
||||
const functionWithoutName = identity(() => function() {});
|
||||
function foo() {}
|
||||
|
||||
expect((<any>functionWithoutName).name).toBeFalsy();
|
||||
expect((<any>foo).name).toEqual('foo');
|
||||
expect(functionWithoutName.name).toBeFalsy();
|
||||
expect(foo.name).toEqual('foo');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function identity(a: any /** TODO #9100 */) {
|
||||
function identity<T>(a: T): T {
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -12,18 +12,16 @@ import {EventEmitter} from '../src/event_emitter';
|
||||
|
||||
{
|
||||
describe('EventEmitter', () => {
|
||||
let emitter: EventEmitter<any>;
|
||||
let emitter: EventEmitter<number>;
|
||||
|
||||
beforeEach(() => {
|
||||
emitter = new EventEmitter();
|
||||
});
|
||||
|
||||
it('should call the next callback', done => {
|
||||
emitter.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(99);
|
||||
done();
|
||||
}
|
||||
emitter.subscribe((value: number) => {
|
||||
expect(value).toEqual(99);
|
||||
done();
|
||||
});
|
||||
emitter.emit(99);
|
||||
});
|
||||
@@ -42,7 +40,7 @@ import {EventEmitter} from '../src/event_emitter';
|
||||
it('should work when no throw callback is provided', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {
|
||||
error: () => {
|
||||
done();
|
||||
}
|
||||
});
|
||||
@@ -52,7 +50,7 @@ import {EventEmitter} from '../src/event_emitter';
|
||||
it('should call the return callback', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {},
|
||||
error: () => {},
|
||||
complete: () => {
|
||||
done();
|
||||
}
|
||||
@@ -63,7 +61,7 @@ import {EventEmitter} from '../src/event_emitter';
|
||||
it('should subscribe to the wrapper synchronously', () => {
|
||||
let called = false;
|
||||
emitter.subscribe({
|
||||
next: (value: any) => {
|
||||
next: () => {
|
||||
called = true;
|
||||
}
|
||||
});
|
||||
@@ -73,19 +71,18 @@ import {EventEmitter} from '../src/event_emitter';
|
||||
});
|
||||
|
||||
it('delivers next and error events synchronously', done => {
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
const log: number[] = [];
|
||||
|
||||
emitter.subscribe({
|
||||
next: (x: any) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 2]);
|
||||
},
|
||||
error: (err: any) => {
|
||||
log.push(err);
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.subscribe(
|
||||
(x: number) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 2]);
|
||||
},
|
||||
(err: any) => {
|
||||
log.push(err);
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
done();
|
||||
});
|
||||
log.push(1);
|
||||
emitter.emit(2);
|
||||
log.push(3);
|
||||
@@ -94,14 +91,14 @@ import {EventEmitter} from '../src/event_emitter';
|
||||
});
|
||||
|
||||
it('delivers next and complete events synchronously', () => {
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
const log: number[] = [];
|
||||
|
||||
emitter.subscribe({
|
||||
next: (x: any) => {
|
||||
next: (x: number) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 2]);
|
||||
},
|
||||
error: null,
|
||||
error: undefined,
|
||||
complete: () => {
|
||||
log.push(4);
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
@@ -116,9 +113,9 @@ import {EventEmitter} from '../src/event_emitter';
|
||||
});
|
||||
|
||||
it('delivers events asynchronously when forced to async mode', done => {
|
||||
const e = new EventEmitter(true);
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
e.subscribe((x: any) => {
|
||||
const e = new EventEmitter<number>(true);
|
||||
const log: number[] = [];
|
||||
e.subscribe((x) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 3, 2]);
|
||||
done();
|
||||
|
||||
@@ -26,7 +26,7 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
});
|
||||
|
||||
it('should pass arguments to the wrapped function', () => {
|
||||
fakeAsync((foo: any /** TODO #9100 */, bar: any /** TODO #9100 */) => {
|
||||
fakeAsync((foo: string, bar: string) => {
|
||||
expect(foo).toEqual('foo');
|
||||
expect(bar).toEqual('bar');
|
||||
})('foo', 'bar');
|
||||
@@ -40,7 +40,7 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
it('should throw on nested calls', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => {
|
||||
fakeAsync((): any /** TODO #9100 */ => null)();
|
||||
fakeAsync((): null => null)();
|
||||
})();
|
||||
}).toThrowError('fakeAsync() calls can not be nested');
|
||||
});
|
||||
@@ -76,7 +76,7 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
}));
|
||||
|
||||
it('should run chained thens', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
const log = new Log<number>();
|
||||
|
||||
resolvedPromise.then((_) => log.add(1)).then((_) => log.add(2));
|
||||
|
||||
@@ -87,7 +87,7 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
}));
|
||||
|
||||
it('should run Promise created in Promise', fakeAsync(() => {
|
||||
const log = new Log();
|
||||
const log = new Log<number>();
|
||||
|
||||
resolvedPromise.then((_) => {
|
||||
log.add(1);
|
||||
@@ -245,9 +245,7 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
|
||||
it('should be able to cancel periodic timers from a callback', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
let id: any /** TODO #9100 */;
|
||||
|
||||
id = setInterval(() => {
|
||||
const id = setInterval(() => {
|
||||
cycles++;
|
||||
clearInterval(id);
|
||||
}, 10);
|
||||
@@ -261,7 +259,7 @@ const ProxyZoneSpec: {assertPresent: () => void} = (Zone as any)['ProxyZoneSpec'
|
||||
|
||||
it('should clear periodic timers', fakeAsync(() => {
|
||||
let cycles = 0;
|
||||
const id = setInterval(() => {
|
||||
setInterval(() => {
|
||||
cycles++;
|
||||
}, 10);
|
||||
|
||||
|
||||
@@ -744,7 +744,7 @@ class NeedsContentChild implements AfterContentInit, AfterContentChecked {
|
||||
get child() {
|
||||
return this._child;
|
||||
}
|
||||
logs: any[] /** TODO #9100 */ = [];
|
||||
logs: (string|null)[][] = [];
|
||||
|
||||
ngAfterContentInit() {
|
||||
this.logs.push(['init', this.child ? this.child.text : null]);
|
||||
@@ -778,7 +778,7 @@ class NeedsViewChild implements AfterViewInit, AfterViewChecked {
|
||||
get child() {
|
||||
return this._child;
|
||||
}
|
||||
logs: any[] /** TODO #9100 */ = [];
|
||||
logs: (string|null)[][] = [];
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.logs.push(['init', this.child ? this.child.text : null]);
|
||||
|
||||
@@ -20,7 +20,7 @@ import {fakeAsync, tick} from '@angular/core/testing';
|
||||
log = '';
|
||||
});
|
||||
|
||||
function logAppend(item: any /** TODO #9100 */) {
|
||||
function logAppend(item: string) {
|
||||
log += (log.length == 0 ? '' : ', ') + item;
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ import {fakeAsync, tick} from '@angular/core/testing';
|
||||
}));
|
||||
|
||||
it('should provides query list as an argument', fakeAsync(() => {
|
||||
let recorded: any /** TODO #9100 */;
|
||||
let recorded: any; /** TODO #9100, replace with QueryList when #48004 is merged */
|
||||
queryList.changes.subscribe({
|
||||
next: (v: any) => {
|
||||
recorded = v;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, getDebugNode, NgZone, RendererFactory2} from '@angular/core';
|
||||
import {Subscription} from 'rxjs';
|
||||
|
||||
|
||||
/**
|
||||
@@ -43,12 +44,12 @@ export class ComponentFixture<T> {
|
||||
private _renderer: RendererFactory2|null|undefined;
|
||||
private _isStable: boolean = true;
|
||||
private _isDestroyed: boolean = false;
|
||||
private _resolve: ((result: any) => void)|null = null;
|
||||
private _promise: Promise<any>|null = null;
|
||||
private _onUnstableSubscription: any /** TODO #9100 */ = null;
|
||||
private _onStableSubscription: any /** TODO #9100 */ = null;
|
||||
private _onMicrotaskEmptySubscription: any /** TODO #9100 */ = null;
|
||||
private _onErrorSubscription: any /** TODO #9100 */ = null;
|
||||
private _resolve: ((result: boolean) => void)|null = null;
|
||||
private _promise: Promise<boolean>|null = null;
|
||||
private _onUnstableSubscription: Subscription|null = null;
|
||||
private _onStableSubscription: Subscription|null = null;
|
||||
private _onMicrotaskEmptySubscription: Subscription|null = null;
|
||||
private _onErrorSubscription: Subscription|null = null;
|
||||
|
||||
constructor(
|
||||
public componentRef: ComponentRef<T>, public ngZone: NgZone|null,
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
export function getTypeOf(instance: any /** TODO #9100 */) {
|
||||
return instance.constructor;
|
||||
}
|
||||
|
||||
export function instantiateType(type: Function, params: any[] = []) {
|
||||
return new (<any>type)(...params);
|
||||
}
|
||||
@@ -9,19 +9,19 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class Log {
|
||||
logItems: any[];
|
||||
export class Log<T = string> {
|
||||
logItems: T[];
|
||||
|
||||
constructor() {
|
||||
this.logItems = [];
|
||||
}
|
||||
|
||||
add(value: any /** TODO #9100 */): void {
|
||||
add(value: T): void {
|
||||
this.logItems.push(value);
|
||||
}
|
||||
|
||||
fn(value: any /** TODO #9100 */) {
|
||||
return (a1: any = null, a2: any = null, a3: any = null, a4: any = null, a5: any = null) => {
|
||||
fn(value: T) {
|
||||
return () => {
|
||||
this.logItems.push(value);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user