Skip to content

Commit ab2d969

Browse files
chore: apply strict typescript checking (#6680)
Applying Typescript checks to the code, including strict null checks that raise errors on unhandled `null` or `undefined` types. Also adding the typescript check to the build step, to raise error on TS errors.
1 parent cf1d320 commit ab2d969

21 files changed

+136
-61
lines changed

astro.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import { rehypeOptimizeStatic } from './plugins/rehype-optimize-static';
1414
import { rehypeTasklistEnhancer } from './plugins/rehype-tasklist-enhancer';
1515
import react from '@astrojs/react';
1616
import { remarkGraphvizPlugin } from './plugins/remark-graphviz';
17-
import dotenv from 'dotenv';
17+
import dotenv, { DotenvPopulateInput } from 'dotenv';
1818
import vue from '@astrojs/vue';
1919
import sitemap from '@astrojs/sitemap';
2020
import { remarkAlgolia } from './plugins/remark-algolia';
2121

2222
dotenv.config({
2323
path: `.env.${process.env.NODE_ENV}`,
2424
});
25-
dotenv.populate(process.env, {
25+
dotenv.populate(process.env as DotenvPopulateInput, {
2626
PUBLIC_ALGOLIA_APP_ID: '81GKA2I1R0',
2727
PUBLIC_ALGOLIA_INDEX_NAME: 'docs-pages-dev',
2828
PUBLIC_ALGOLIA_SEARCH_KEY: '6fce1b6d8ccf82a6601a169c0167c0e3',

integrations/astro-asides.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,23 @@ function remarkAsides(): unified.Plugin<[], mdast.Root> {
4848
let title: string | undefined;
4949
remove(node, (child) => {
5050
if ((child.data as { directiveLabel?: string })?.directiveLabel) {
51-
if ('children' in child && 'value' in child.children[0]) {
52-
title = child.children[0].value;
51+
if ('children' in child && 'value' in (child.children as any)[0]) {
52+
title = (child.children as any)[0].value;
5353
}
5454
return true;
5555
}
5656
});
5757

58-
// Replace this node with the aside component it represents.
59-
parent.children[index] = makeComponentNode(
60-
AsideTagname,
61-
{ attributes: { type, title } },
62-
...node.children as mdast.BlockContent[]
63-
);
58+
if (index !== undefined ) {
59+
// Replace this node with the aside component it represents.
60+
parent.children[index] = makeComponentNode(
61+
AsideTagname,
62+
{ attributes: { type, title } },
63+
...node.children as mdast.BlockContent[]
64+
);
65+
} else {
66+
throw new Error('Invalid index for parent node');
67+
}
6468
});
6569
};
6670

integrations/astro-youtube-embed.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ function remarkYoutubeEmbed(): unified.Plugin<[], mdast.Root> {
2828

2929
remove(node, (child) => {
3030
if ((child.data as { directiveLabel?: string })?.directiveLabel) {
31-
if ('children' in child && 'value' in child.children[0]) {
32-
title = child.children[0].value;
31+
if ('children' in child && 'value' in (child.children as any)[0]) {
32+
title = (child.children as any)[0].value;
3333
}
3434
return true;
3535
}
3636
});
3737

38-
// Replace this node with the aside component it represents.
39-
parent.children[index] = makeComponentNode(
40-
YoutubeTagname,
41-
{ attributes: { title, video: node.attributes.v } },
42-
...node.children as mdast.BlockContent[]
43-
);
38+
if (index !== undefined) {
39+
// Replace this node with the aside component it represents.
40+
parent.children[index] = makeComponentNode(
41+
YoutubeTagname,
42+
{ attributes: { title, video: node.attributes?.v } },
43+
...node.children as mdast.BlockContent[]
44+
);
45+
} else {
46+
throw new Error('Youtube directive has no parent');
47+
}
4448
});
4549
};
4650

package-lock.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"dev": "astro dev",
77
"start": "astro dev",
8-
"build": "astro build",
8+
"build": "tsc && astro build",
99
"cf-build": "./cf-build.sh",
1010
"test": "vitest",
1111
"preview": "astro preview",
@@ -15,6 +15,7 @@
1515
"@actions/core": "^1.11.1",
1616
"@astrojs/mdx": "^4.2.3",
1717
"@astrojs/sitemap": "^3.3.0",
18+
"@astrojs/ts-plugin": "^1.10.4",
1819
"@babel/core": "^7.26.10",
1920
"@types/hast": "^3.0.4",
2021
"@types/html-escaper": "^3.0.4",
@@ -148,4 +149,4 @@
148149
"@rollup/rollup-linux-arm64-gnu": "^4.39.0",
149150
"@rollup/rollup-linux-x64-gnu": "^4.39.0"
150151
}
151-
}
152+
}

src/@types/astro.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '*.astro' {
2+
const Component: any;
3+
export default Component;
4+
}

src/components/HeadSEO.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface Props {
1111
const { content, canonicalURL } = Astro.props;
1212
const ogImageUrl = getOgImageUrl(canonicalURL.pathname);
1313
const imageSrc = ogImageUrl;
14-
const canonicalImageSrc = new URL(imageSrc, Astro.site);
14+
const canonicalImageSrc = imageSrc ? new URL(imageSrc, Astro.site) : undefined;
1515
const imageAlt = imageSrc === ogImageUrl ? '' : "Mergify's logo with text Docs on blue background";
1616
const siteDescription =
1717
'Learn how to use Mergify, the powerful pull request automation tool that helps teams merge code faster and more safely. Automate your entire pull request workflow, from code review to deployment, and save time and frustration.';

src/components/LeftSidebar/NavGroup.astro

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ const { navGroup, currentPageMatch } = Astro.props as Props;
5454
const uuid = this.dataset.uuid;
5555
const storedNavState = window.localStorage.getItem('navState');
5656
let isOpen = false;
57-
if (storedNavState !== null) {
57+
if (!uuid) {
58+
console.warn('No uuid found for nav-group');
59+
return;
60+
}
61+
if (storedNavState !== null && uuid) {
5862
const navState = JSON.parse(storedNavState);
5963
isOpen = navState[uuid];
6064
}
@@ -65,12 +69,12 @@ const { navGroup, currentPageMatch } = Astro.props as Props;
6569
);
6670

6771
if (isOpen) {
68-
navGroupDetails.setAttribute('open', '');
72+
navGroupDetails?.setAttribute('open', '');
6973
} else {
70-
navGroupDetails.removeAttribute('open');
74+
navGroupDetails?.removeAttribute('open');
7175
}
7276

73-
navGroupTitle.addEventListener('click', () => {
77+
navGroupTitle?.addEventListener('click', () => {
7478
const storedNavState = window.localStorage.getItem('navState');
7579
let navState = { uuid: true };
7680
if (storedNavState !== null) {

src/components/LeftSidebar/NavLink.astro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export interface Props {
99
const { currentPageMatch, navItem } = Astro.props as Props;
1010
const isHomepage = navItem.path === '/';
1111
const isHomepageMatch = isHomepage && currentPageMatch === '';
12-
const isPageMatch = !isHomepage && currentPageMatch.endsWith(removeLeadingSlash(navItem.path));
12+
const isPageMatch =
13+
!isHomepage && currentPageMatch.endsWith(removeLeadingSlash(navItem.path ?? ''));
1314
---
1415

1516
<li class="nav-link">

src/components/MergeQueueCalculator/MergeQueueCalculator.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import './MergeQueueCalculator.scss';
88
import Stat from './Stat';
99

1010
function MergeQueueCalculator() {
11-
const [ciTime, setCiTime] = useState(30);
12-
const [prPerHour, setPrPerHour] = useState(10);
13-
const [ciUsagePct, setCiUsagePct] = useState(100);
14-
const [successRatio, setSuccessRatio] = useState(98);
15-
const [throughput, setThroughput] = useState(null);
16-
const [speculativeChecks, setSpeculativeChecks] = useState(null);
17-
const [batchSize, setBatchSize] = useState(null);
18-
const [latency, setLatency] = useState(null);
11+
const [ciTime, setCiTime] = useState<number>(30);
12+
const [prPerHour, setPrPerHour] = useState<number>(10);
13+
const [ciUsagePct, setCiUsagePct] = useState<number>(100);
14+
const [successRatio, setSuccessRatio] = useState<number>(98);
15+
const [throughput, setThroughput] = useState<number | null>(null);
16+
const [speculativeChecks, setSpeculativeChecks] = useState<number | null>(null);
17+
const [batchSize, setBatchSize] = useState<number | null>(null);
18+
const [latency, setLatency] = useState<number | null>(null);
1919

2020
const calculate = () => {
2121
const calculatedBatchSize = Math.ceil(100 / ciUsagePct);

0 commit comments

Comments
 (0)