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

@@ -45,7 +45,7 @@ export interface CssAnimationPropertyOptions<T, 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>);
public readonly getDefault: symbol;
@@ -55,12 +55,16 @@ export class Property<T extends ViewBase, U> implements TypedPropertyDescriptor<
public nativeValueChange(T, U): void;
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>);
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> {
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.
* @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.

View File

@@ -184,3 +184,7 @@ export class Cache extends observable.Observable implements definition.Cache {
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 { CoercibleProperty, CssProperty, Style, View, Template, KeyedTemplate, Length, Property, Color, Observable } from "../core/view";
import { ListView as ListViewDefinition, ItemsSource, ItemEventData } from ".";
import { CoercibleProperty, CssProperty, Style, View, Template, KeyedTemplate, Length, Property, Color, Observable, EventData } from "../core/view";
import { parse, parseMultipleTemplates } from "../builder";
import { Label } from "../label";
import { ObservableArray, ChangedData } from "../../data/observable-array";
@@ -129,9 +129,15 @@ export abstract class ListViewBase extends View implements ListViewDefinition {
rowHeightProperty.coerce(this);
}
}
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.
*/

View File

@@ -1,7 +1,7 @@
import { Page as PageDefinition, NavigatedData, ShownModallyData } from ".";
import {
ContentView, View, eachDescendant, Property, CssProperty, Color, isIOS,
booleanConverter, resetCSSProperties, Style
booleanConverter, resetCSSProperties, Style, EventData
} from "../content-view";
import { Frame, topmost as topmostFrame, resolvePageFromEntry } from "../frame";
import { ActionBar } from "../action-bar";
@@ -297,6 +297,15 @@ export class PageBase extends ContentView implements PageDefinition {
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.

View File

@@ -1,5 +1,5 @@
import { Placeholder as PlaceholderDefinition, CreateViewEventData } from "."
import { View } from "../core/view"
import { View, EventData } from "../core/view"
export class Placeholder extends View implements PlaceholderDefinition {
public static creatingViewEvent = "creatingView";
@@ -9,4 +9,8 @@ export class Placeholder extends View implements PlaceholderDefinition {
this.notify(args);
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 { View } from "../core/view"
import { View, EventData } from "../core/view"
export class Placeholder extends View implements PlaceholderDefinition {
public static creatingViewEvent = "creatingView";
@@ -9,4 +9,8 @@ export class Placeholder extends View implements PlaceholderDefinition {
this.notify(args);
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 { ContentView, Property, makeParser, makeValidator } from "../content-view";
import { ScrollView as ScrollViewDefinition, Orientation, ScrollEventData } from ".";
import { ContentView, Property, makeParser, makeValidator, EventData } from "../content-view";
import { profile } from "../../profiling";
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 _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"));
export const orientationProperty = new Property<ScrollViewBase, Orientation>({

View File

@@ -1,7 +1,7 @@
import { SegmentedBar as SegmentedBarDefinition, SegmentedBarItem as SegmentedBarItemDefinition, SelectedIndexChangedEventData } from ".";
import {
ViewBase, View, AddChildFromBuilder, AddArrayFromBuilder,
Property, CoercibleProperty, InheritedCssProperty, Color, Style
Property, CoercibleProperty, InheritedCssProperty, Color, Style, EventData
} 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;

View File

@@ -1,7 +1,7 @@
import { TabView as TabViewDefinition, TabViewItem as TabViewItemDefinition, SelectedIndexChangedEventData } from ".";
import {
View, ViewBase, Style, Property, CssProperty, CoercibleProperty,
Color, isIOS, AddArrayFromBuilder, AddChildFromBuilder
Color, isIOS, AddArrayFromBuilder, AddChildFromBuilder, EventData
} 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>({
name: "selectedIndex", defaultValue: -1, affectsLayout: isIOS,

View File

@@ -1,5 +1,5 @@
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";
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")
}
}
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);