build: upgrade to TypeScript 2.6 (#21144)

Fixes #20653

PR Close #21144
This commit is contained in:
Chuck Jazdzewski
2017-12-22 09:36:47 -08:00
committed by Igor Minar
parent 83c1383701
commit 83d207d0a7
45 changed files with 331 additions and 215 deletions

View File

@ -124,7 +124,7 @@ export class AppVersion implements UpdateSource {
// No response has been found yet. Maybe this group will have one.
return group.handleFetch(req, context);
}, Promise.resolve(null));
}, Promise.resolve<Response|null>(null));
// The result of the above is the asset response, if there is any, or null otherwise. Return the
// asset
@ -142,7 +142,7 @@ export class AppVersion implements UpdateSource {
}
return group.handleFetch(req, context);
}, Promise.resolve(null));
}, Promise.resolve<Response|null>(null));
// If the data caching group returned a response, go with it.
if (data !== null) {

View File

@ -276,6 +276,7 @@ export abstract class AssetGroup {
const cache = await this.cache;
// Start with the set of all cached URLs.
return (await cache.keys())
.map(request => request.url)
// Exclude the URLs which have hashes.
.filter(url => !this.hashes.has(url));
}
@ -608,4 +609,4 @@ export class LazyAssetGroup extends AssetGroup {
}
}, Promise.resolve());
}
}
}

View File

@ -51,7 +51,7 @@ export class CacheTable implements Table {
'delete'(key: string): Promise<boolean> { return this.cache.delete(this.request(key)); }
keys(): Promise<string[]> {
return this.cache.keys().then(keys => keys.map(key => key.substr(1)));
return this.cache.keys().then(requests => requests.map(req => req.url.substr(1)));
}
read(key: string): Promise<any> {
@ -66,4 +66,4 @@ export class CacheTable implements Table {
write(key: string, value: Object): Promise<void> {
return this.cache.put(this.request(key), this.adapter.newResponse(JSON.stringify(value)));
}
}
}

View File

@ -25,33 +25,6 @@ interface ExtendableEvent extends Event {
waitUntil(fn: Promise<any>): void;
}
// CacheStorage API
interface Cache {
add(request: Request): Promise<void>;
addAll(requestArray: Array<Request>): Promise<void>;
'delete'(request: Request, options?: CacheStorageOptions): Promise<boolean>;
keys(request?: Request, options?: CacheStorageOptions): Promise<Array<string>>;
match(request: Request, options?: CacheStorageOptions): Promise<Response|undefined>;
matchAll(request: Request, options?: CacheStorageOptions): Promise<Array<Response>>;
put(request: Request|string, response: Response): Promise<void>;
}
interface CacheStorage {
'delete'(cacheName: string): Promise<boolean>;
has(cacheName: string): Promise<boolean>;
keys(): Promise<Array<string>>;
match(request: Request, options?: CacheStorageOptions): Promise<Response|undefined>;
open(cacheName: string): Promise<Cache>;
}
interface CacheStorageOptions {
cacheName?: string;
ignoreMethod?: boolean;
ignoreSearch?: boolean;
ignoreVary?: boolean;
}
// Client API
declare class Client {
@ -145,4 +118,4 @@ interface ServiceWorkerGlobalScope {
fetch(request: Request|string): Promise<Response>;
skipWaiting(): Promise<void>;
}
}

View File

@ -41,7 +41,7 @@ export class MockCacheStorage implements CacheStorage {
if (!this.caches.has(name)) {
this.caches.set(name, new MockCache(this.origin));
}
return this.caches.get(name) !;
return this.caches.get(name) as any;
}
async match(req: Request): Promise<Response|undefined> {
@ -74,7 +74,7 @@ export class MockCacheStorage implements CacheStorage {
}
}
export class MockCache implements Cache {
export class MockCache {
private cache = new Map<string, Response>();
constructor(private origin: string, hydrated?: DehydratedCache) {
@ -122,7 +122,6 @@ export class MockCache implements Cache {
return res !;
}
async matchAll(request?: Request|string, options?: CacheQueryOptions): Promise<Response[]> {
if (request === undefined) {
return Array.from(this.cache.values());
@ -149,7 +148,7 @@ export class MockCache implements Cache {
dehydrate(): DehydratedCache {
const dehydrated: DehydratedCache = {};
Array.from(this.cache.keys()).forEach(url => {
const resp = this.cache.get(url) !as MockResponse;
const resp = this.cache.get(url) as MockResponse;
const dehydratedResp = {
body: resp._body,
status: resp.status,
@ -163,4 +162,4 @@ export class MockCache implements Cache {
});
return dehydrated;
}
}
}

View File

@ -57,17 +57,26 @@ export class MockBody implements Body {
export class MockHeaders implements Headers {
map = new Map<string, string>();
[Symbol.iterator]() { return this.map[Symbol.iterator](); }
append(name: string, value: string): void { this.map.set(name, value); }
delete (name: string): void { this.map.delete(name); }
entries() { return this.map.entries(); }
forEach(callback: Function): void { this.map.forEach(callback as any); }
get(name: string): string|null { return this.map.get(name) || null; }
has(name: string): boolean { return this.map.has(name); }
keys() { return this.map.keys(); }
set(name: string, value: string): void { this.map.set(name, value); }
values() { return this.map.values(); }
}
export class MockRequest extends MockBody implements Request {
@ -91,13 +100,12 @@ export class MockRequest extends MockBody implements Request {
throw 'Not implemented';
}
this.url = input;
if (init.headers !== undefined) {
if (init.headers instanceof MockHeaders) {
this.headers = init.headers;
const headers = init.headers as{[key: string]: string};
if (headers !== undefined) {
if (headers instanceof MockHeaders) {
this.headers = headers;
} else {
Object.keys(init.headers).forEach(header => {
this.headers.set(header, init.headers[header]);
});
Object.keys(headers).forEach(header => { this.headers.set(header, headers[header]); });
}
}
if (init.mode !== undefined) {
@ -134,13 +142,12 @@ export class MockResponse extends MockBody implements Response {
super(typeof body === 'string' ? body : null);
this.status = (init.status !== undefined) ? init.status : 200;
this.statusText = init.statusText || 'OK';
if (init.headers !== undefined) {
if (init.headers instanceof MockHeaders) {
this.headers = init.headers;
const headers = init.headers as{[key: string]: string};
if (headers !== undefined) {
if (headers instanceof MockHeaders) {
this.headers = headers;
} else {
Object.keys(init.headers).forEach(header => {
this.headers.set(header, init.headers[header]);
});
Object.keys(headers).forEach(header => { this.headers.set(header, headers[header]); });
}
}
if (init.type !== undefined) {

View File

@ -212,4 +212,4 @@ export function tmpHashTable(manifest: Manifest): Map<string, string> {
map.set(url, hash);
});
return map;
}
}