1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
//// [variableDeclaratorResolvedDuringContextualTyping.ts]
module WinJS {
export interface ValueCallback {
(value: any): any;
}
export interface EventCallback {
(value: any): void;
}
export interface ErrorCallback {
(error: any): any;
}
export interface ProgressCallback {
(progress: any): any;
}
export declare class Promise {
constructor(init: (complete: ValueCallback, error: ErrorCallback, progress: ProgressCallback) => void, oncancel?: any);
static as(value: any): Promise;
static join(promises: { [name: string]: Promise; }): Promise;
static join(promises: Promise[]): Promise;
static any(promises: Promise[]): Promise;
static timeout(delay: number): Promise;
static wrapError(error: any): Promise;
static is(value: any): boolean;
static addEventListener(type: string, fn: EventCallback);
public then(success?: ValueCallback, error?: ErrorCallback, progress?: ProgressCallback): Promise;
public done(success?: ValueCallback, error?: ErrorCallback, progress?: ProgressCallback): void;
public cancel(): void;
}
export declare class TPromise<V> {
constructor(init: (complete: (value: V) => void, error: (err: any) => void, progress: ProgressCallback) => void, oncancel?: any);
public then<U>(success?: (value: V) => TPromise<U>, error?: (err: any) => TPromise<U>, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => TPromise<U>, error?: (err: any) => U, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => U, error?: (err: any) => TPromise<U>, progress?: ProgressCallback): TPromise<U>;
public then<U>(success?: (value: V) => U, error?: (err: any) => U, progress?: ProgressCallback): TPromise<U>;
public done(success?: (value: V) => void, error?: (err: any) => any, progress?: ProgressCallback): void;
public cancel(): void;
public static as<ValueType>(value: ValueType): TPromise<ValueType>;
public static timeout(delay: number): TPromise<void>;
public static join<ValueType>(promises: TPromise<ValueType>[]): TPromise<ValueType[]>;
public static any<ValueType>(promises: TPromise<ValueType>[]): TPromise<ValueType>;
public static wrapError<ValueType>(error: any): TPromise<ValueType>;
}
export interface IXHROptions {
type?: string;
url?: string;
user?: string;
password?: string;
responseType?: string;
headers?: any;
customRequestInitializer?: (req: any) => void;
data?: any;
}
}
module Services {
export interface IRequestService {
/**
* Returns the URL that can be used to access the provided service. The optional second argument can
* be provided to narrow down the request URL to a specific file system resource. The third argument
* allows to specify to return a fully absolute server URL.
*/
getRequestUrl(service: string, path?: string): string;
getRequestUrl(service: string, path?: string, absolute?: boolean): string;
/**
* Wraps the call into WinJS.XHR to allow for mocking and telemetry. Use this instead
* of calling WinJS.XHR directly.
*/
makeRequest(options: WinJS.IXHROptions): WinJS.Promise;
}
}
module Errors {
export class ConnectionError /* extends Error */ {
constructor(request: XMLHttpRequest) {
}
}
}
module Files {
export interface IUploadResult {
stat: string;
isNew: boolean;
}
}
interface XMLHttpRequest {
status: number;
responseText: string;
statusText: string;
}
class FileService {
private requestService: Services.IRequestService;
public uploadData(): WinJS.TPromise<Files.IUploadResult> {
var path = "";
return this.requestService.makeRequest({
url: this.requestService.getRequestUrl('root', path),
type: 'POST',
headers: {},
data: "someData"
}).then((response: XMLHttpRequest) => {
var result: IUploadResult = { // This should be error
stat: this.jsonToStat(newFilePath, "someString"), // _this needs to be emitted to the js file
isNew: response.status === 201
};
return WinJS.TPromise.as<Files.IUploadResult>(result);
}, (xhr: XMLHttpRequest) => {
return WinJS.Promise.wrapError(new Errors.ConnectionError(xhr));
});
}
}
//// [variableDeclaratorResolvedDuringContextualTyping.js]
var WinJS;
(function (WinJS) {
})(WinJS || (WinJS = {}));
var Errors;
(function (Errors) {
var ConnectionError /* extends Error */ = /** @class */ (function () {
function ConnectionError(request) {
}
return ConnectionError;
}());
Errors.ConnectionError = ConnectionError;
})(Errors || (Errors = {}));
var FileService = /** @class */ (function () {
function FileService() {
}
FileService.prototype.uploadData = function () {
var _this = this;
var path = "";
return this.requestService.makeRequest({
url: this.requestService.getRequestUrl('root', path),
type: 'POST',
headers: {},
data: "someData"
}).then(function (response) {
var result = {
stat: _this.jsonToStat(newFilePath, "someString"),
isNew: response.status === 201
};
return WinJS.TPromise.as(result);
}, function (xhr) {
return WinJS.Promise.wrapError(new Errors.ConnectionError(xhr));
});
};
return FileService;
}());
|