Skip to content

Commit 10ded43

Browse files
authored
Turn on the "noUncheckedIndexedAccess" flag in all TS config files (#3587)
1 parent d1fdc13 commit 10ded43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+301
-305
lines changed

packages/browser-types/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"allowJs": true,
66
"skipLibCheck": true,
77
"strict": true,
8+
"noUncheckedIndexedAccess": true,
89
"noEmit": false,
910
"declaration": true,
1011
"outDir": "dist",

packages/cache-tags/src/index.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,6 @@ export function getCacheTag(
121121
}
122122
}
123123

124-
/**
125-
* Get the cache tag for a given URL.
126-
*/
127-
export function getCacheTagForURL(url: string | URL) {
128-
const parsedURL = url instanceof URL ? url : new URL(url);
129-
return getCacheTag({
130-
tag: 'url',
131-
hostname: parsedURL.hostname,
132-
});
133-
}
134-
135124
/**
136125
* Get the tags for a computed content source.
137126
*/
@@ -182,7 +171,7 @@ export function getComputedContentSourceCacheTags(
182171
break;
183172
default:
184173
// Do not throw for unknown dependency types
185-
// as it might mean we are lacking behind the API version
174+
// as it might mean we are lagging behind the API version
186175
break;
187176
}
188177
});
@@ -198,9 +187,8 @@ export function getComputedContentSourceCacheTags(
198187
}
199188

200189
// We invalidate the computed content when a new version of the integration is deployed.
201-
202190
if (source.type.startsWith('integration:')) {
203-
const integration = source.type.split(':')[1];
191+
const integration = source.type.split(':')[1]!;
204192
tags.push(
205193
getCacheTag({
206194
tag: 'integration',

packages/cache-tags/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"allowJs": true,
66
"skipLibCheck": true,
77
"strict": true,
8+
"noUncheckedIndexedAccess": true,
89
"noEmit": false,
910
"declaration": true,
1011
"outDir": "dist",

packages/colors/src/transformations.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type RGBColor = [number, number, number];
88
type OKLABColor = { L: number; A: number; B: number };
99
type OKLCHColor = { L: number; C: number; H: number };
1010

11-
const D65 = [95.047, 100.0, 108.883]; // Reference white (D65)
11+
const D65 = [95.047, 100.0, 108.883] as const; // Reference white (D65)
1212

1313
export enum ColorCategory {
1414
backgrounds = 'backgrounds',
@@ -211,8 +211,8 @@ export function colorScale(
211211
const result = [];
212212

213213
for (let index = 0; index < mapping.length; index++) {
214-
const targetL =
215-
foregroundColor.L * mapping[index] + backgroundColor.L * (1 - mapping[index]);
214+
const step = mapping[index]!;
215+
const targetL = foregroundColor.L * step + backgroundColor.L * (1 - step);
216216

217217
if (
218218
index === 8 &&
@@ -295,7 +295,7 @@ export function rgbArrayToHex(rgb: RGBColor): string {
295295

296296
export function getColor(percentage: number, start: RGBColor, end: RGBColor) {
297297
const rgb = end.map((channel, index) => {
298-
return Math.round(channel + percentage * (start[index] - channel));
298+
return Math.round(channel + percentage * (start[index]! - channel));
299299
});
300300

301301
return rgbArrayToHex(rgb as RGBColor);
@@ -392,14 +392,14 @@ export function xyzToLab65(xyz: [number, number, number]): {
392392
B: number;
393393
} {
394394
const [x, y, z] = xyz.map((v, i) => {
395-
const scaled = v / D65[i];
395+
const scaled = v / D65[i]!;
396396
return scaled > 0.008856 ? Math.cbrt(scaled) : 7.787 * scaled + 16 / 116;
397397
});
398398

399399
return {
400-
L: 116 * y - 16,
401-
A: 500 * (x - y),
402-
B: 200 * (y - z),
400+
L: 116 * y! - 16,
401+
A: 500 * (x! - y!),
402+
B: 200 * (y! - z!),
403403
};
404404
}
405405

packages/colors/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"allowJs": true,
66
"skipLibCheck": true,
77
"strict": true,
8+
"noUncheckedIndexedAccess": true,
89
"noEmit": false,
910
"declaration": true,
1011
"outDir": "dist",

packages/fonts/src/getDefaultFont.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function getBestUnicodeRange(text: string, ranges: Record<string, string>): stri
6767

6868
const body = token.slice(2); // drop "U+"
6969
const [startHex, endHex] = body.split('-');
70-
const start = Number.parseInt(startHex, 16);
70+
const start = Number.parseInt(startHex!, 16);
7171
const end = endHex ? Number.parseInt(endHex, 16) : start;
7272

7373
if (Number.isNaN(start) || Number.isNaN(end) || end < start) return null;
@@ -92,7 +92,7 @@ function getBestUnicodeRange(text: string, ranges: Record<string, string>): stri
9292

9393
for (const [label, rangesArr] of Object.entries(parsed)) {
9494
if (rangesArr.some(([lo, hi]) => cp >= lo && cp <= hi)) {
95-
hits[label]++;
95+
hits[label]!++;
9696
}
9797
}
9898
}

packages/fonts/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"module": "ESNext",
55
"target": "es2022",
66
"strict": true,
7+
"noUncheckedIndexedAccess": true,
78
"esModuleInterop": true,
89
"skipLibCheck": true,
910
"moduleResolution": "bundler",

packages/gitbook/openNext/customWorkers/script/updateWrangler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const args = process.argv.slice(2);
1111
const versionId = args[0];
1212

1313
// The preview URL is in the format https://<versionId>-gitbook-open-v2-server-preview.gitbook.workers.dev
14-
const previewHostname = `${versionId.split('-')[0]}-gitbook-open-v2-server-preview.gitbook.workers.dev`;
14+
const previewHostname = `${versionId?.split('-')[0]}-gitbook-open-v2-server-preview.gitbook.workers.dev`;
1515

1616
let updatedFile = file.replace(
1717
/"PREVIEW_HOSTNAME": "TO_REPLACE"/,

packages/gitbook/src/components/AI/server-actions/api.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ export async function streamRenderAIMessage(
3939

4040
if (message.steps[stepIndex]) {
4141
message.steps = [...message.steps];
42+
// @ts-expect-error
4243
message.steps[stepIndex] = { ...message.steps[stepIndex] };
44+
// @ts-expect-error
4345
callback(message.steps[stepIndex]);
4446
} else {
4547
message.steps = [
@@ -52,6 +54,7 @@ export async function streamRenderAIMessage(
5254
},
5355
},
5456
];
57+
// @ts-expect-error
5558
callback(message.steps[stepIndex]);
5659
}
5760
};

packages/gitbook/src/components/AIActions/AIActionsDropdown.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,15 @@ function DefaultAction(props: AIActionsDropdownProps) {
111111
(assistant) => assistant.ui === true && assistant.pageAction
112112
);
113113

114-
if (assistants.length) {
115-
return <OpenAIAssistant assistant={assistants[0]} type="button" />;
114+
const assistant = assistants[0];
115+
if (assistant) {
116+
return <OpenAIAssistant assistant={assistant} type="button" />;
116117
}
117118

118119
if (actions.markdown) {
119120
return (
120121
<CopyMarkdown
121-
isDefaultAction={!assistants.length}
122+
isDefaultAction={!assistant}
122123
markdownPageUrl={markdownPageUrl}
123124
type="button"
124125
/>

0 commit comments

Comments
 (0)