Skip to content

Commit fa6e4b1

Browse files
stepankuzmingithub-actions[bot]
authored andcommitted
Migrate more files to strict TypeScript (internal-16412)
GitOrigin-RevId: 9c1ebf25556bef251fdb8f394e3ceba5850089e6
1 parent 3ee3fc6 commit fa6e4b1

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/style-spec/error/parsing_error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export default class ParsingError {
1111
this.error = error;
1212
this.message = error.message;
1313
const match = error.message.match(LINE_NUMBER_RE);
14-
this.line = match ? parseInt(match[1], 10) : 0;
14+
this.line = match && match[1] ? parseInt(match[1], 10) : 0;
1515
}
1616
}

src/style-spec/expression/types/resolved_image.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from '../../util/assert';
12
import {ImageId} from './image_id';
23
import {ImageVariant} from './image_variant';
34

@@ -56,7 +57,10 @@ export default class ResolvedImage {
5657
}
5758

5859
static from(image: string | ResolvedImage): ResolvedImage {
59-
return typeof image === 'string' ? ResolvedImage.build({name: image}) : image;
60+
if (typeof image !== 'string') return image;
61+
const resolved = ResolvedImage.build({name: image});
62+
assert(resolved);
63+
return resolved;
6064
}
6165

6266
static build(

src/util/url.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,14 @@ export function getURLExtension(url: string): string {
88
}
99
}
1010

11-
export function setQueryParameters(
12-
url: string,
13-
params: {
14-
[key: string]: string;
15-
},
16-
): string {
11+
export function setQueryParameters(url: string, params: Record<string, string>): string {
1712
const paramStart = url.indexOf('?');
18-
if (paramStart < 0) return `${url}?${new URLSearchParams(params).toString()}`;
19-
20-
const searchParams = new URLSearchParams(url.slice(paramStart));
21-
for (const key in params) {
22-
searchParams.set(key, params[key]);
13+
const base = paramStart < 0 ? url : url.slice(0, paramStart);
14+
const searchParams = new URLSearchParams(paramStart < 0 ? '' : url.slice(paramStart));
15+
for (const [key, value] of Object.entries(params)) {
16+
searchParams.set(key, value);
2317
}
24-
25-
return `${url.slice(0, paramStart)}?${searchParams.toString()}`;
18+
return `${base}?${searchParams}`;
2619
}
2720

2821
type StripQueryParameters = {

src/util/worker_pool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class WorkerPool {
1010
static workerCount: number;
1111

1212
active: Partial<Record<number | string, boolean>>;
13-
workers: Array<Worker>;
13+
workers: Array<Worker> | null;
1414
name?: string;
1515
constructor(name?: string) {
1616
this.active = {};

tsconfig.strict.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
"./3d-style/style/indoor_active_floor_strategy.ts",
106106
"./src/placement/global_placement_priority.ts",
107107
"./src/placement/placement_rules.ts",
108-
"./src/placement/symbol_source.ts"
108+
"./src/placement/symbol_source.ts",
109+
"./src/style-spec/error/parsing_error.ts",
110+
"./src/util/url.ts",
111+
"./src/util/worker_pool.ts",
112+
"./src/style-spec/expression/types/resolved_image.ts"
109113
]
110114
}

0 commit comments

Comments
 (0)