Type safety improvements [#287] (#335)

* Work through linter issues related to non-null checks and any.
This commit is contained in:
Brandon Liu
2024-01-29 22:46:08 +08:00
committed by GitHub
parent 9a29c5a78a
commit d7e24d046e
2 changed files with 33 additions and 23 deletions

View File

@@ -77,7 +77,7 @@ export const leafletRasterLayer = (source: PMTiles, options: any) => {
// copied from MapLibre /util/ajax.ts // copied from MapLibre /util/ajax.ts
type RequestParameters = { type RequestParameters = {
url: string; url: string;
headers?: any; headers?: unknown;
method?: "GET" | "POST" | "PUT"; method?: "GET" | "POST" | "PUT";
body?: string; body?: string;
type?: "string" | "json" | "arrayBuffer" | "image"; type?: "string" | "json" | "arrayBuffer" | "image";
@@ -87,7 +87,7 @@ type RequestParameters = {
type ResponseCallback = ( type ResponseCallback = (
error?: Error | null, error?: Error | null,
data?: any | null, data?: unknown | null,
cacheControl?: string | null, cacheControl?: string | null,
expires?: string | null expires?: string | null
) => void; ) => void;

View File

@@ -296,10 +296,13 @@ export class FetchSource implements Source {
async getBytes( async getBytes(
offset: number, offset: number,
length: number, length: number,
signal?: AbortSignal passedSignal?: AbortSignal
): Promise<RangeResponse> { ): Promise<RangeResponse> {
let controller; let controller: AbortController | undefined;
if (!signal) { let signal: AbortSignal | undefined;
if (passedSignal) {
signal = passedSignal;
} else {
// TODO check this works or assert 206 // TODO check this works or assert 206
controller = new AbortController(); controller = new AbortController();
signal = controller.signal; signal = controller.signal;
@@ -567,9 +570,10 @@ export class ResolvedValueCache {
async getHeader(source: Source, currentEtag?: string): Promise<Header> { async getHeader(source: Source, currentEtag?: string): Promise<Header> {
const cacheKey = source.getKey(); const cacheKey = source.getKey();
if (this.cache.has(cacheKey)) { const cacheValue = this.cache.get(cacheKey);
this.cache.get(cacheKey)!.lastUsed = this.counter++; if (cacheValue) {
const data = this.cache.get(cacheKey)?.data; cacheValue.lastUsed = this.counter++;
const data = cacheValue.data;
return data as Header; return data as Header;
} }
@@ -603,9 +607,10 @@ export class ResolvedValueCache {
const cacheKey = `${source.getKey()}|${ const cacheKey = `${source.getKey()}|${
header.etag || "" header.etag || ""
}|${offset}|${length}`; }|${offset}|${length}`;
if (this.cache.has(cacheKey)) { const cacheValue = this.cache.get(cacheKey);
this.cache.get(cacheKey)!.lastUsed = this.counter++; if (cacheValue) {
const data = this.cache.get(cacheKey)?.data; cacheValue.lastUsed = this.counter++;
const data = cacheValue.data;
return data as Entry[]; return data as Entry[];
} }
@@ -634,9 +639,10 @@ export class ResolvedValueCache {
const cacheKey = `${source.getKey()}|${ const cacheKey = `${source.getKey()}|${
header.etag || "" header.etag || ""
}|${offset}|${length}`; }|${offset}|${length}`;
if (this.cache.has(cacheKey)) { const cacheValue = this.cache.get(cacheKey);
this.cache.get(cacheKey)!.lastUsed = this.counter++; if (cacheValue) {
const data = await this.cache.get(cacheKey)?.data; cacheValue.lastUsed = this.counter++;
const data = await cacheValue.data;
return data as ArrayBuffer; return data as ArrayBuffer;
} }
@@ -704,9 +710,10 @@ export class SharedPromiseCache {
async getHeader(source: Source, currentEtag?: string): Promise<Header> { async getHeader(source: Source, currentEtag?: string): Promise<Header> {
const cacheKey = source.getKey(); const cacheKey = source.getKey();
if (this.cache.has(cacheKey)) { const cacheValue = this.cache.get(cacheKey);
this.cache.get(cacheKey)!.lastUsed = this.counter++; if (cacheValue) {
const data = await this.cache.get(cacheKey)?.data; cacheValue.lastUsed = this.counter++;
const data = await cacheValue.data;
return data as Header; return data as Header;
} }
@@ -739,9 +746,10 @@ export class SharedPromiseCache {
const cacheKey = `${source.getKey()}|${ const cacheKey = `${source.getKey()}|${
header.etag || "" header.etag || ""
}|${offset}|${length}`; }|${offset}|${length}`;
if (this.cache.has(cacheKey)) { const cacheValue = this.cache.get(cacheKey);
this.cache.get(cacheKey)!.lastUsed = this.counter++; if (cacheValue) {
const data = await this.cache.get(cacheKey)?.data; cacheValue.lastUsed = this.counter++;
const data = await cacheValue.data;
return data as Entry[]; return data as Entry[];
} }
@@ -769,9 +777,10 @@ export class SharedPromiseCache {
const cacheKey = `${source.getKey()}|${ const cacheKey = `${source.getKey()}|${
header.etag || "" header.etag || ""
}|${offset}|${length}`; }|${offset}|${length}`;
if (this.cache.has(cacheKey)) { const cacheValue = this.cache.get(cacheKey);
this.cache.get(cacheKey)!.lastUsed = this.counter++; if (cacheValue) {
const data = await this.cache.get(cacheKey)?.data; cacheValue.lastUsed = this.counter++;
const data = await cacheValue.data;
return data as ArrayBuffer; return data as ArrayBuffer;
} }
@@ -817,6 +826,7 @@ export class SharedPromiseCache {
} }
} }
// biome-ignore lint: that's just how its capitalized
export class PMTiles { export class PMTiles {
source: Source; source: Source;
cache: Cache; cache: Cache;