From 7bb457ef2b815318dce5de21f87a7686b3211109 Mon Sep 17 00:00:00 2001 From: Hristo Deshev Date: Fri, 24 Feb 2017 13:13:52 +0200 Subject: [PATCH] Upgrade to TypeScript 2.2 Fix typings, remove Request, etc clashes with the new lib.dom.d.ts --- apps/package.json | 2 +- package.json | 7 +-- tests/app/TKUnit.ts | 8 ++-- tests/package.json | 2 +- tns-core-modules/declarations.d.ts | 69 +++--------------------------- 5 files changed, 15 insertions(+), 73 deletions(-) diff --git a/apps/package.json b/apps/package.json index ebcddf27b..233a67c71 100644 --- a/apps/package.json +++ b/apps/package.json @@ -22,6 +22,6 @@ "babylon": "6.8.3", "lazy": "1.0.11", "nativescript-dev-typescript": "^0.3.0", - "typescript": "~2.1.6" + "typescript": "~2.2.1" } } diff --git a/package.json b/package.json index e890298b0..fac4b0436 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "license": "Apache-2.0", "devDependencies": { + "@types/node": "^7.0.5", "chai": "3.2.0", "concurrently": "^2.1.0", "grunt": "1.0.1", @@ -17,8 +18,8 @@ "grunt-exec": "1.0.1", "grunt-mkdir": "1.0.0", "grunt-shell": "2.1.0", - "grunt-ts": "6.0.0-beta.11", "grunt-simple-mocha": "0.4.1", + "grunt-ts": "6.0.0-beta.11", "grunt-typedoc": "0.2.4", "http-server": "^0.9.0", "markdown-snippet-injector": "0.1.1", @@ -27,8 +28,8 @@ "shelljs": "^0.7.0", "time-grunt": "1.3.0", "tslint": "^4.4.2", - "typedoc": "0.5.6", - "typescript": "~2.1.5" + "typedoc": "https://github.com/hdeshev/typedoc/blob/npm/typedoc-no-types.tgz?raw=true", + "typescript": "~2.2.1" }, "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", diff --git a/tests/app/TKUnit.ts b/tests/app/TKUnit.ts index 0b59b6dae..5fcc7e5de 100644 --- a/tests/app/TKUnit.ts +++ b/tests/app/TKUnit.ts @@ -234,8 +234,8 @@ export function assertEqual(actual: T, e * Assert two json like objects are deep equal. */ export function assertDeepEqual(actual, expected, path: any[] = []): void { - let typeofActual = typeof actual; - let typeofExpected = typeof expected; + let typeofActual: string = typeof actual; + let typeofExpected: string = typeof expected; if (typeofActual !== typeofExpected) { throw new Error("At /" + path.join("/") + " types of actual " + typeofActual + " and expected " + typeofExpected + " differ."); } else if (typeofActual === "object" || typeofActual === "array") { @@ -290,8 +290,8 @@ export function assertDeepEqual(actual, expected, path: any[] = []): void { } export function assertDeepSuperset(actual, expected, path: any[] = []): void { - let typeofActual = typeof actual; - let typeofExpected = typeof expected; + let typeofActual: string = typeof actual; + let typeofExpected: string = typeof expected; if (typeofActual !== typeofExpected) { throw new Error("At /" + path.join("/") + " types of actual " + typeofActual + " and expected " + typeofExpected + " differ."); } else if (typeofActual === "object" || typeofActual === "array") { diff --git a/tests/package.json b/tests/package.json index c53305030..bfaf5ea03 100644 --- a/tests/package.json +++ b/tests/package.json @@ -22,6 +22,6 @@ "babylon": "6.8.0", "filewalker": "0.1.2", "lazy": "1.0.11", - "typescript": "~2.1.6" + "typescript": "~2.2.1" } } diff --git a/tns-core-modules/declarations.d.ts b/tns-core-modules/declarations.d.ts index 5627ff435..289ceecae 100644 --- a/tns-core-modules/declarations.d.ts +++ b/tns-core-modules/declarations.d.ts @@ -1,26 +1,5 @@ /* tslint:disable:no-unused-variable */ -declare class Request { - constructor(input: string|Request, init?: RequestInit); - method: string; - url: string; - headers: Headers; - context: RequestContext; - referrer: string; - mode: RequestMode; - credentials: RequestCredentials; - cache: RequestCache; -} - -interface RequestInit { - method?: string; - headers?: HeaderInit|{ [index: string]: string }; - body?: BodyInit; - mode?: RequestMode; - credentials?: RequestCredentials; - cache?: RequestCache; -} - declare enum RequestContext { "audio", "beacon", "cspreport", "download", "embed", "eventsource", "favicon", "fetch", "font", "form", "frame", "hyperlink", "iframe", "image", "imageset", "import", @@ -29,19 +8,15 @@ declare enum RequestContext { "xmlhttprequest", "xslt" } +// Extend the lib.dom.d.ts Body interface with `formData` +interface Body { + formData() : Promise; +} + declare enum RequestMode { "same-origin", "no-cors", "cors" } declare enum RequestCredentials { "omit", "same-origin", "include" } declare enum RequestCache { "default", "no-store", "reload", "no-cache", "force-cache", "only-if-cached" } -declare class Headers { - append(name: string, value: string): void; - delete(name: string): void; - get(name: string): string; - getAll(name: string): Array; - has(name: string): boolean; - set(name: string, value: string): void; -} - interface Blob { readonly size: number; readonly type: string; @@ -60,41 +35,7 @@ interface BlobPropertyBag { endings?: string; } -declare class Body { - bodyUsed: boolean; - /* - arrayBuffer(): Promise; - blob(): Promise; - */ - formData(): Promise; - json(): Promise; - text(): Promise; -} - -declare class Response extends Body { - constructor(body?: BodyInit, init?: ResponseInit); - error(): Response; - redirect(url: string, status: number): Response; - type: ResponseType; - url: string; - status: number; - ok: boolean; - statusText: string; - headers: Headers; - clone(): Response; -} - -declare enum ResponseType { "basic", "cors", "default", "error", "opaque" } - -declare class ResponseInit { - status: number; - statusText: string; - headers: HeaderInit; -} - declare type HeaderInit = Headers|Array; -declare type BodyInit = Blob|FormData|string; -declare type RequestInfo = Request|string; declare function fetch(url: string, init?: RequestInit): Promise;