Fix TypeScript 2.4 errors, introduced mainly due weak types and covariant checking for callbacks (#4476)

This commit is contained in:
Panayot Cankov
2017-07-03 11:57:00 +03:00
committed by Alexander Vakrilov
parent 9e6498c29a
commit 8adb2fdfef
20 changed files with 92 additions and 23 deletions

View File

@ -30,7 +30,7 @@
"tslint": "^4.4.2", "tslint": "^4.4.2",
"typedoc": "^0.5.10", "typedoc": "^0.5.10",
"typedoc-plugin-external-module-name": "git://github.com/PanayotCankov/typedoc-plugin-external-module-name.git#with-js", "typedoc-plugin-external-module-name": "git://github.com/PanayotCankov/typedoc-plugin-external-module-name.git#with-js",
"typescript": "~2.2.1" "typescript": "^2.4.1"
}, },
"scripts": { "scripts": {
"setup": "npm run dev-link-tns-platform-declarations && npm run dev-link-tns-core-modules && npm run dev-link-tests && npm run dev-link-apps", "setup": "npm run dev-link-tns-platform-declarations && npm run dev-link-tns-core-modules && npm run dev-link-tests && npm run dev-link-apps",

View File

@ -214,7 +214,7 @@ export function assertNotEqual(actual: any, expected: any, message?: string) {
} }
} }
export function assertEqual<T extends { equals?(arg: T): boolean }>(actual: T, expected: T, message: string = '') { export function assertEqual<T extends { equals?(arg: T): boolean } | any>(actual: T, expected: T, message: string = '') {
if (!types.isNullOrUndefined(actual) if (!types.isNullOrUndefined(actual)
&& !types.isNullOrUndefined(expected) && !types.isNullOrUndefined(expected)
&& types.getClass(actual) === types.getClass(expected) && types.getClass(actual) === types.getClass(expected)

View File

@ -1,6 +1,7 @@
import { import {
AndroidActivityBundleEventData, AndroidActivityEventData, ApplicationEventData, OrientationChangedEventData, AndroidActivityBundleEventData, AndroidActivityEventData, ApplicationEventData, OrientationChangedEventData,
AndroidApplication as AndroidApplicationDefinition AndroidApplication as AndroidApplicationDefinition,
AndroidActivityResultEventData, AndroidActivityBackPressedEventData, AndroidActivityRequestPermissionsEventData
} from "."; } from ".";
import { import {
@ -102,6 +103,19 @@ export class AndroidApplication extends Observable implements AndroidApplication
} }
} }
} }
export interface AndroidApplication {
on(eventNames: string, callback: (data: AndroidActivityEventData) => void, thisArg?: any);
on(event: "activityCreated", callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any);
on(event: "activityDestroyed", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
on(event: "activityStarted", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
on(event: "activityPaused", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
on(event: "activityResumed", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
on(event: "activityStopped", callback: (args: AndroidActivityEventData) => void, thisArg?: any);
on(event: "saveActivityState", callback: (args: AndroidActivityBundleEventData) => void, thisArg?: any);
on(event: "activityResult", callback: (args: AndroidActivityResultEventData) => void, thisArg?: any);
on(event: "activityBackPressed", callback: (args: AndroidActivityBackPressedEventData) => void, thisArg?: any);
on(event: "activityRequestPermissions", callback: (args: AndroidActivityRequestPermissionsEventData) => void, thisArg?: any);
}
const androidApp = new AndroidApplication(); const androidApp = new AndroidApplication();
// use the exports object instead of 'export var' due to global namespace collision // use the exports object instead of 'export var' due to global namespace collision

View File

@ -324,3 +324,7 @@ export class ObservableArray<T> extends observable.Observable implements observa
return this._array.reduceRight(callbackfn, initialValue); return this._array.reduceRight(callbackfn, initialValue);
} }
} }
export interface ObservableArray<T> {
on(eventNames: string, callback: (data: observable.EventData) => void, thisArg?: any);
on(event: "change", callback: (args: observableArrayDef.ChangedData<T>) => void, thisArg?: any);
}

View File

@ -1,4 +1,4 @@
import { Observable } from "../observable"; import { Observable, EventData } from "../observable";
import * as virtualArrayDef from "."; import * as virtualArrayDef from ".";
const CHANGE = "change"; const CHANGE = "change";
@ -158,3 +158,8 @@ export class VirtualArray<T> extends Observable implements virtualArrayDef.Virtu
} }
} }
} }
export interface VirtualArray<T> {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: "itemsLoading", callback: (args: virtualArrayDef.ItemsLoading) => void, thisArg?: any);
on(event: "change", callback: (args: virtualArrayDef.ChangedData<T>) => void, thisArg?: any);
}

View File

@ -23,7 +23,7 @@ global.moduleMerge = function (sourceExports: any, destExports: any) {
import * as timerModule from "../timer"; import * as timerModule from "../timer";
import * as dialogsModule from "../ui/dialogs"; import * as dialogsModule from "../ui/dialogs";
type ModuleLoader = () => any; type ModuleLoader = (name?: string) => any;
const modules: Map<string, ModuleLoader> = new Map<string, ModuleLoader>(); const modules: Map<string, ModuleLoader> = new Map<string, ModuleLoader>();
global.registerModule = function(name: string, loader: ModuleLoader): void { global.registerModule = function(name: string, loader: ModuleLoader): void {

View File

@ -242,7 +242,7 @@ export function fromNativeSource(source: any): ImageSource {
return image.setNativeSource(source) ? image : null; return image.setNativeSource(source) ? image : null;
} }
export function fromUrl(url: string): Promise<ImageSource> { export function fromUrl(url: string): Promise<ImageSourceDefinition> {
ensureHttp(); ensureHttp();
return http.getImage(url); return http.getImage(url);
} }

View File

@ -161,7 +161,7 @@ const profileMethodUnnamed = (target, key, descriptor) => {
} }
function profileMethodNamed(name: string): MethodDecorator { function profileMethodNamed(name: string): MethodDecorator {
return (target, key, descriptor) => { return (target, key, descriptor: PropertyDescriptor) => {
// save a reference to the original method this way we keep the values currently in the // save a reference to the original method this way we keep the values currently in the
// descriptor and don't overwrite what another decorator might have done to the descriptor. // descriptor and don't overwrite what another decorator might have done to the descriptor.

View File

@ -45,7 +45,7 @@ export interface CssAnimationPropertyOptions<T, U> {
readonly valueConverter?: (value: string) => U; readonly valueConverter?: (value: string) => U;
} }
export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<U> { export class Property<T extends ViewBase, U> {
constructor(options: PropertyOptions<T, U>); constructor(options: PropertyOptions<T, U>);
public readonly getDefault: symbol; public readonly getDefault: symbol;
@ -55,12 +55,16 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<
public nativeValueChange(T, U): void; public nativeValueChange(T, U): void;
public isSet(instance: T): boolean; public isSet(instance: T): boolean;
} }
export interface Property<T extends ViewBase, U> extends TypedPropertyDescriptor<U> {
}
export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> implements TypedPropertyDescriptor<U> { export class CoercibleProperty<T extends ViewBase, U> extends Property<T, U> {
constructor(options: CoerciblePropertyOptions<T, U>); constructor(options: CoerciblePropertyOptions<T, U>);
public readonly coerce: (target: T) => void; public readonly coerce: (target: T) => void;
} }
export interface CoercibleProperty<T extends ViewBase, U> extends TypedPropertyDescriptor<U> {
}
export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> { export class InheritedProperty<T extends ViewBase, U> extends Property<T, U> {
constructor(options: PropertyOptions<T, U>); constructor(options: PropertyOptions<T, U>);

View File

@ -27,7 +27,7 @@ export module inputType {
* The alert() method displays an alert box with a specified message. * The alert() method displays an alert box with a specified message.
* @param message Specifies the text to display in the alert box. * @param message Specifies the text to display in the alert box.
*/ */
export function alert(message: string): Promise<void>; export function alert(message: string | number | boolean): Promise<void>;
/** /**
* The alert() method displays an alert box with a specified message. * The alert() method displays an alert box with a specified message.

View File

@ -184,3 +184,7 @@ export class Cache extends observable.Observable implements definition.Cache {
this._download(request); this._download(request);
} }
} }
export interface Cache {
on(eventNames: string, callback: (args: observable.EventData) => void , thisArg?: any);
on(event: "downloaded", callback: (args: definition.DownloadedData) => void , thisArg?: any);
}

View File

@ -1,5 +1,5 @@
import { ListView as ListViewDefinition, ItemsSource } from "."; import { ListView as ListViewDefinition, ItemsSource, ItemEventData } from ".";
import { CoercibleProperty, CssProperty, Style, View, Template, KeyedTemplate, Length, Property, Color, Observable } from "../core/view"; import { CoercibleProperty, CssProperty, Style, View, Template, KeyedTemplate, Length, Property, Color, Observable, EventData } from "../core/view";
import { parse, parseMultipleTemplates } from "../builder"; import { parse, parseMultipleTemplates } from "../builder";
import { Label } from "../label"; import { Label } from "../label";
import { ObservableArray, ChangedData } from "../../data/observable-array"; import { ObservableArray, ChangedData } from "../../data/observable-array";
@ -129,9 +129,15 @@ export abstract class ListViewBase extends View implements ListViewDefinition {
rowHeightProperty.coerce(this); rowHeightProperty.coerce(this);
} }
} }
ListViewBase.prototype.recycleNativeView = true; ListViewBase.prototype.recycleNativeView = true;
export interface ListViewBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: "itemLoading", callback: (args: ItemEventData) => void, thisArg?: any);
on(event: "itemTap", callback: (args: ItemEventData) => void, thisArg?: any);
on(event: "loadMoreItems", callback: (args: EventData) => void, thisArg?: any);
}
/** /**
* Represents the property backing the items property of each ListView instance. * Represents the property backing the items property of each ListView instance.
*/ */

View File

@ -1,7 +1,7 @@
import { Page as PageDefinition, NavigatedData, ShownModallyData } from "."; import { Page as PageDefinition, NavigatedData, ShownModallyData } from ".";
import { import {
ContentView, View, eachDescendant, Property, CssProperty, Color, isIOS, ContentView, View, eachDescendant, Property, CssProperty, Color, isIOS,
booleanConverter, resetCSSProperties, Style booleanConverter, resetCSSProperties, Style, EventData
} from "../content-view"; } from "../content-view";
import { Frame, topmost as topmostFrame, resolvePageFromEntry } from "../frame"; import { Frame, topmost as topmostFrame, resolvePageFromEntry } from "../frame";
import { ActionBar } from "../action-bar"; import { ActionBar } from "../action-bar";
@ -297,6 +297,15 @@ export class PageBase extends ContentView implements PageDefinition {
eachDescendant(this, resetCssValuesFunc); eachDescendant(this, resetCssValuesFunc);
} }
} }
export interface PageBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
on(event: "navigatingTo", callback: (args: NavigatedData) => void, thisArg?: any): void;
on(event: "navigatedTo", callback: (args: NavigatedData) => void, thisArg?: any): void;
on(event: "navigatingFrom", callback: (args: NavigatedData) => void, thisArg?: any): void;
on(event: "navigatedFrom", callback: (args: NavigatedData) => void, thisArg?: any): void;
on(event: "showingModally", callback: (args: ShownModallyData) => void, thisArg?: any): void;
on(event: "shownModally", callback: (args: ShownModallyData) => void, thisArg?: any);
}
/** /**
* Dependency property used to hide the Navigation Bar in iOS and the Action Bar in Android. * Dependency property used to hide the Navigation Bar in iOS and the Action Bar in Android.

View File

@ -1,5 +1,5 @@
import { Placeholder as PlaceholderDefinition, CreateViewEventData } from "." import { Placeholder as PlaceholderDefinition, CreateViewEventData } from "."
import { View } from "../core/view" import { View, EventData } from "../core/view"
export class Placeholder extends View implements PlaceholderDefinition { export class Placeholder extends View implements PlaceholderDefinition {
public static creatingViewEvent = "creatingView"; public static creatingViewEvent = "creatingView";
@ -9,4 +9,8 @@ export class Placeholder extends View implements PlaceholderDefinition {
this.notify(args); this.notify(args);
return <android.view.View>args.view; return <android.view.View>args.view;
} }
}
export interface Placeholder {
on(eventNames: string, callback: (args: EventData) => void);
on(event: "creatingView", callback: (args: CreateViewEventData) => void);
} }

View File

@ -1,5 +1,5 @@
import { Placeholder as PlaceholderDefinition, CreateViewEventData } from "." import { Placeholder as PlaceholderDefinition, CreateViewEventData } from "."
import { View } from "../core/view" import { View, EventData } from "../core/view"
export class Placeholder extends View implements PlaceholderDefinition { export class Placeholder extends View implements PlaceholderDefinition {
public static creatingViewEvent = "creatingView"; public static creatingViewEvent = "creatingView";
@ -9,4 +9,8 @@ export class Placeholder extends View implements PlaceholderDefinition {
this.notify(args); this.notify(args);
return args.view; return args.view;
} }
}
export interface Placeholder {
on(eventNames: string, callback: (args: EventData) => void);
on(event: "creatingView", callback: (args: CreateViewEventData) => void);
} }

View File

@ -1,5 +1,5 @@
import { ScrollView as ScrollViewDefinition, Orientation } from "."; import { ScrollView as ScrollViewDefinition, Orientation, ScrollEventData } from ".";
import { ContentView, Property, makeParser, makeValidator } from "../content-view"; import { ContentView, Property, makeParser, makeValidator, EventData } from "../content-view";
import { profile } from "../../profiling"; import { profile } from "../../profiling";
export * from "../content-view"; export * from "../content-view";
@ -81,6 +81,10 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe
public abstract scrollToHorizontalOffset(value: number, animated: boolean); public abstract scrollToHorizontalOffset(value: number, animated: boolean);
public abstract _onOrientationChanged(); public abstract _onOrientationChanged();
} }
export interface ScrollViewBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: "scroll", callback: (args: ScrollEventData) => void, thisArg?: any);
}
const converter = makeParser<Orientation>(makeValidator("horizontal", "vertical")); const converter = makeParser<Orientation>(makeValidator("horizontal", "vertical"));
export const orientationProperty = new Property<ScrollViewBase, Orientation>({ export const orientationProperty = new Property<ScrollViewBase, Orientation>({

View File

@ -1,7 +1,7 @@
import { SegmentedBar as SegmentedBarDefinition, SegmentedBarItem as SegmentedBarItemDefinition, SelectedIndexChangedEventData } from "."; import { SegmentedBar as SegmentedBarDefinition, SegmentedBarItem as SegmentedBarItemDefinition, SelectedIndexChangedEventData } from ".";
import { import {
ViewBase, View, AddChildFromBuilder, AddArrayFromBuilder, ViewBase, View, AddChildFromBuilder, AddArrayFromBuilder,
Property, CoercibleProperty, InheritedCssProperty, Color, Style Property, CoercibleProperty, InheritedCssProperty, Color, Style, EventData
} from "../core/view"; } from "../core/view";
export * from "../core/view"; export * from "../core/view";
@ -89,6 +89,10 @@ export abstract class SegmentedBarBase extends View implements SegmentedBarDefin
} }
} }
} }
export interface SegmentedBarBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: "selectedIndexChanged", callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
}
SegmentedBarBase.prototype.recycleNativeView = true; SegmentedBarBase.prototype.recycleNativeView = true;

View File

@ -1,7 +1,7 @@
import { TabView as TabViewDefinition, TabViewItem as TabViewItemDefinition, SelectedIndexChangedEventData } from "."; import { TabView as TabViewDefinition, TabViewItem as TabViewItemDefinition, SelectedIndexChangedEventData } from ".";
import { import {
View, ViewBase, Style, Property, CssProperty, CoercibleProperty, View, ViewBase, Style, Property, CssProperty, CoercibleProperty,
Color, isIOS, AddArrayFromBuilder, AddChildFromBuilder Color, isIOS, AddArrayFromBuilder, AddChildFromBuilder, EventData
} from "../core/view"; } from "../core/view";
export * from "../core/view"; export * from "../core/view";
@ -182,6 +182,10 @@ export class TabViewBase extends View implements TabViewDefinition, AddChildFrom
} }
} }
} }
export interface TabViewBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: "selectedIndexChanged", callback: (args: SelectedIndexChangedEventData) => void, thisArg?: any);
}
export const selectedIndexProperty = new CoercibleProperty<TabViewBase, number>({ export const selectedIndexProperty = new CoercibleProperty<TabViewBase, number>({
name: "selectedIndex", defaultValue: -1, affectsLayout: isIOS, name: "selectedIndex", defaultValue: -1, affectsLayout: isIOS,

View File

@ -1,5 +1,5 @@
import { WebView as WebViewDefinition, LoadEventData, NavigationType } from "."; import { WebView as WebViewDefinition, LoadEventData, NavigationType } from ".";
import { View, Property } from "../core/view"; import { View, Property, EventData } from "../core/view";
import { File, knownFolders, path } from "../../file-system"; import { File, knownFolders, path } from "../../file-system";
export { File, knownFolders, path, NavigationType }; export { File, knownFolders, path, NavigationType };
@ -92,5 +92,10 @@ export abstract class WebViewBase extends View implements WebViewDefinition {
throw new Error("Property url of WebView is deprecated. Use src instead") throw new Error("Property url of WebView is deprecated. Use src instead")
} }
} }
export interface WebViewBase {
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
on(event: "loadFinished", callback: (args: LoadEventData) => void, thisArg?: any);
on(event: "loadStarted", callback: (args: LoadEventData) => void, thisArg?: any);
}
srcProperty.register(WebViewBase); srcProperty.register(WebViewBase);

View File

@ -107930,7 +107930,6 @@ declare module javax {
glQueryMatrixxOES(mantissa: java.nio.IntBuffer, exponent: java.nio.IntBuffer): number; glQueryMatrixxOES(mantissa: java.nio.IntBuffer, exponent: java.nio.IntBuffer): number;
} }
interface IGL { interface IGL {
__javax_microedition_khronos_opengles_IGL?: any;
} }
} }
export module egl { export module egl {
@ -107939,7 +107938,6 @@ declare module javax {
static class: java.lang.Class<javax.microedition.khronos.egl.EGLSurface>; static class: java.lang.Class<javax.microedition.khronos.egl.EGLSurface>;
} }
interface IEGL { interface IEGL {
__javax_microedition_khronos_egl_IEGL?: any;
} }
export class EGL10 implements javax.microedition.khronos.egl.IEGL, javax.microedition.khronos.egl.IEGL10 { export class EGL10 implements javax.microedition.khronos.egl.IEGL, javax.microedition.khronos.egl.IEGL10 {
constructor(implementation: javax.microedition.khronos.egl.IEGL10); constructor(implementation: javax.microedition.khronos.egl.IEGL10);