fix(typings): repair broken typechecks

We had the typechecker disabled by accident, and many problems snuck in

Fixes #4507

Closes #4508
This commit is contained in:
Alex Eagle 2015-10-05 16:02:21 -07:00 committed by Alex Eagle
parent ae6f549f10
commit 6093e28b61
19 changed files with 99 additions and 76 deletions

View File

@ -58,7 +58,7 @@ export function CONST_EXPR<T>(expr: T): T {
return expr;
}
export function CONST(): ClassDecorator {
export function CONST(): ClassDecorator & PropertyDecorator {
return (target) => target;
}

View File

@ -18,7 +18,13 @@ export interface ClassDefinition {
*
* See {@link Class} for example of usage.
*/
constructor: (Function | any[]);
constructor: Function | any[];
/**
* Other methods on the class. Note that values should have type 'Function' but TS requires
* all properties to have a narrower type than the index signature.
*/
[x: string]: Type | Function | any[];
}
/**

View File

@ -93,7 +93,7 @@ export function main() {
});
it("should throw when more than one custom accessor is provided", () => {
var customAccessor = new SpyValueAccessor();
var customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError();
});
});

View File

@ -156,7 +156,7 @@ export function main() {
{"one": new Control("111"), "nested": new ControlGroup({"two": new Control("222")})});
expect(g.value).toEqual({"one": "111", "nested": {"two": "222"}});
g.controls["nested"].controls["two"].updateValue("333");
(<Control>(g.controls["nested"].find("two"))).updateValue("333");
expect(g.value).toEqual({"one": "111", "nested": {"two": "333"}});
});

View File

@ -11,8 +11,7 @@ import {
xit,
Log,
isInInnerZone,
browserDetection,
TIMEOUT_INTERVAL_FOR_SLOW_BROWSERS
browserDetection
} from 'angular2/test_lib';
import {PromiseCompleter, PromiseWrapper, TimerWrapper} from 'angular2/src/core/facade/async';

View File

@ -1,11 +1,11 @@
import {Component, View, LifecycleEvent, ViewEncapsulation, OnChanges} from 'angular2/angular2';
import {Component, View, ViewEncapsulation, OnChanges} from 'angular2/angular2';
import {TimerWrapper} from 'angular2/src/core/facade/async';
import {isPresent} from 'angular2/src/core/facade/lang';
// TODO(jelbourn): Ink ripples.
// TODO(jelbourn): Make the `isMosueDown` stuff done with one global listener.
// TODO(jelbourn): Make the `isMouseDown` stuff done with one global listener.
@Component({
selector: '[md-button]:not(a), [md-fab]:not(a), [md-raised-button]:not(a)',

View File

@ -1,11 +1,4 @@
import {
Directive,
LifecycleEvent,
Attribute,
Host,
SkipSelf,
AfterContentChecked
} from 'angular2/angular2';
import {Directive, Attribute, Host, SkipSelf, AfterContentChecked} from 'angular2/angular2';
import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async';

View File

@ -1,11 +1,4 @@
import {
Component,
LifecycleEvent,
View,
ViewEncapsulation,
Attribute,
OnChanges
} from 'angular2/angular2';
import {Component, View, ViewEncapsulation, Attribute, OnChanges} from 'angular2/angular2';
import {CONST} from 'angular2/src/core/facade/lang';
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
import {Math} from 'angular2/src/core/facade/math';

View File

@ -2,7 +2,6 @@ import {
Component,
View,
ViewEncapsulation,
LifecycleEvent,
Host,
SkipSelf,
Attribute,

View File

@ -64,12 +64,11 @@ function measureWrapper(func, desc) {
class MultiplyViewResolver extends ViewResolver {
_multiplyBy: number;
_cache: Map<Type, ViewMetadata>;
_cache = new Map<Type, ViewMetadata>();
constructor(multiple: number, components: Type[]) {
super();
this._multiplyBy = multiple;
this._cache = new Map();
ListWrapper.forEach(components, (c) => this._fillCache(c));
}

View File

@ -1,2 +1,3 @@
export var createElement: Function;
export var render: Function;
export var createClass: Function;

View File

@ -10,9 +10,9 @@ document.getElementById("send_echo")
var val = (<HTMLInputElement>document.getElementById("echo_input")).value;
// TODO(jteplitz602): Replace default constructors with real constructors
// once they're in the .d.ts file (#3926)
var args = new UiArguments();
var args = new UiArguments("echo");
args.method = "echo";
var fnArg = new FnArg();
var fnArg = new FnArg(val, PRIMITIVE);
fnArg.value = val;
fnArg.type = PRIMITIVE;
args.args = [fnArg];

47
modules/upgrade/src/angular.d.ts vendored Normal file
View File

@ -0,0 +1,47 @@
declare namespace angular {
function module(prefix: string, dependencies?: string[]);
interface IModule {
directive(selector: string, factory: any): IModule;
value(key: string, value: any): IModule;
run(a: any);
}
interface ICompileService {
(element: Element): (IScope) => void;
}
interface IRootScopeService {
$new(): IScope;
$watch(expr: any, fn?: (a1?: any, a2?: any) => void);
$apply(): any;
$apply(exp: string): any;
$apply(exp: (scope: IScope) => any): any;
}
interface IScope extends IRootScopeService {}
interface IAngularBootstrapConfig {}
interface IDirective {}
interface IAttributes {
$observe(attr: string, fn: (v: string) => void);
}
interface ITranscludeFunction {}
interface IAugmentedJQuery {
bind(name: string, fn: () => void);
}
interface IParseService {
(expression: string): ICompiledExpression;
}
interface ICompiledExpression {
assign(context: any, value: any): any;
}
function element(e: Element);
function bootstrap(e: Element, modules: IModule[], config: IAngularBootstrapConfig);
namespace auto {
interface IInjectorService {
get(key: string): any;
}
}
var version: {major: number};
}
interface Function {
$inject?: string[];
}

View File

@ -26,12 +26,13 @@ export interface AttrProp {
}
export interface ComponentInfo {
type: Type;
selector: string;
inputs: AttrProp[];
outputs: AttrProp[];
}
export function getComponentInfo(type: Type): string {
export function getComponentInfo(type: Type): ComponentInfo {
var resolvedMetadata: DirectiveMetadata = directiveResolver.resolve(type);
var selector = resolvedMetadata.selector;
if (!selector.match(COMPONENT_SELECTOR)) {
@ -59,7 +60,7 @@ export function parseFields(names: string[]): AttrProp[] {
attr: attr,
bracketAttr: `[${attr}]`,
parenAttr: `(${attr})`,
bracketParenAttr: `[(${attr})]`
bracketParenAttr: `[(${attr})]`,
onAttr: `on${capitalAttr}`,
bindAttr: `bind${capitalAttr}`,
bindonAttr: `bindon${capitalAttr}`

View File

@ -1,9 +1,7 @@
///<reference path="../typings/angularjs/angular.d.ts"/>
///<reference path="./angular.d.ts"/>
import {
platform,
PlatformRef,
ApplicationRef,
ComponentRef,
bind,
Directive,
@ -62,7 +60,7 @@ export class UpgradeModule {
this.componentTypes.push(type);
var info: ComponentInfo = getComponentInfo(type);
var factory: Function = ng1ComponentDirective(info, `${this.idPrefix}${info.selector}_c`);
this.ng1Module.directive(info.selector, <any[]>factory);
this.ng1Module.directive(info.selector, <any>factory);
return this;
}
@ -175,7 +173,7 @@ function ng1ComponentDirective(info: ComponentInfo, idPrefix: string): Function
class Ng2ComponentFacade {
component: any = null;
inputChangeCount: number = 0;
inputChanges: StringMap<string, SimpleChange> = null;
inputChanges: {[key: string]: SimpleChange} = null;
hostViewRef: HostViewRef = null;
changeDetector: ChangeDetectorRef = null;
componentScope: angular.IScope;
@ -215,7 +213,7 @@ class Ng2ComponentFacade {
prevValue = value;
}
this.component[prop] = value;
}
};
})(input.prop);
attrs.$observe(input.attr, observeFn);
} else if (attrs.hasOwnProperty(input.bindAttr)) {
@ -284,8 +282,7 @@ class Ng2ComponentFacade {
((getter) => (value) => getter(this.scope, {$event: value}))(getter)
});
} else {
throw new Error(
`Missing emitter '${output.prop}' on component '${this.input.selector}'!`);
throw new Error(`Missing emitter '${output.prop}' on component '${this.info.selector}'!`);
}
}
}

View File

@ -12,7 +12,7 @@ import {
} from 'angular2/test_lib';
import {Component, View, Inject, EventEmitter} from 'angular2/angular2';
import {createUpgradeModule, UpgradeModule, bootstrapHybrid} from 'upgrade/upgrade';
import {createUpgradeModule, UpgradeModule} from 'upgrade/upgrade';
export function main() {
describe('upgrade: ng1 to ng2', () => {
@ -56,7 +56,8 @@ export function main() {
}));
describe('scope/component change-detection', () => {
it('should interleve scope and component expressions', inject([AsyncTestCompleter], (async) {
it('should interleave scope and component expressions',
inject([AsyncTestCompleter], (async) => {
var log = [];
var l = function(value) {
log.push(value);
@ -93,7 +94,7 @@ export function main() {
});
describe('binding from ng1 to ng2', () => {
it('should bind properties, events', inject([AsyncTestCompleter], (async) {
it('should bind properties, events', inject([AsyncTestCompleter], (async) => {
var upgrMod: UpgradeModule = createUpgradeModule();
upgrMod.ng1Module.run(($rootScope) => {
$rootScope.dataA = 'A';
@ -133,26 +134,24 @@ export function main() {
this.twoWayBEmitter = new EventEmitter();
},
onChanges: function(changes) {
var assert =
(prop, value) => {
if (this[prop] != value) {
throw new Error(
`Expected: '${prop}' to be '${value}' but was '${this[prop]}'`);
}
}
var assert = (prop, value) => {
if (this[prop] != value) {
throw new Error(
`Expected: '${prop}' to be '${value}' but was '${this[prop]}'`);
}
};
var assertChange =
(prop, value) => {
assert(prop, value);
if (!changes[prop]) {
throw new Error(`Changes record for '${prop}' not found.`);
}
var actValue = changes[prop].currentValue;
if (actValue != value) {
throw new Error(
`Expected changes record for'${prop}' to be '${value}' but was '${actValue}'`);
}
}
var assertChange = (prop, value) => {
assert(prop, value);
if (!changes[prop]) {
throw new Error(`Changes record for '${prop}' not found.`);
}
var actValue = changes[prop].currentValue;
if (actValue != value) {
throw new Error(
`Expected changes record for'${prop}' to be '${value}' but was '${actValue}'`);
}
};
switch (this.onChangesCount++) {
case 0:

View File

@ -1,12 +0,0 @@
{
"version": "v4",
"repo": "angular/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"angularjs/angular.d.ts": {
"commit": "746b9a892629060bc853e792afff536e0ec4655e"
}
}
}

View File

@ -24,7 +24,7 @@
},
"scripts": {
"preinstall": "node tools/npm/check-node-modules --purge",
"postinstall": "node tools/npm/copy-npm-shrinkwrap && node tools/chromedriverpatch.js && webdriver-manager update && bower install && gulp pubget.dart && tsd reinstall --overwrite --clean --config modules/angular2/tsd.json && tsd reinstall --overwrite --clean --config tools/tsd.json && tsd reinstall --overwrite --config modules/upgrade/tsd.json",
"postinstall": "node tools/npm/copy-npm-shrinkwrap && node tools/chromedriverpatch.js && webdriver-manager update && bower install && gulp pubget.dart && tsd reinstall --overwrite --clean --config modules/angular2/tsd.json && tsd reinstall --overwrite --clean --config tools/tsd.json",
"test": "gulp test.all.js && gulp test.all.dart"
},
"dependencies": {

View File

@ -118,7 +118,7 @@ module.exports = function makeBrowserTree(options, destinationPath) {
});
// Use TypeScript to transpile the *.ts files to ES5
var es5Tree = compileWithTypescript(es5ModulesTree, {
var typescriptOptions = {
allowNonTsExtensions: false,
declaration: false,
emitDecoratorMetadata: true,
@ -131,7 +131,8 @@ module.exports = function makeBrowserTree(options, destinationPath) {
sourceMap: true,
sourceRoot: '.',
target: 'ES5'
});
};
var es5Tree = compileWithTypescript(es5ModulesTree, typescriptOptions);
// Now we add a few more files to the es6 tree that the es5 tree should not see
var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: 'angular2'});