Skip to content

Commit

Permalink
refactor: enable TypeScript strict-null checks
Browse files Browse the repository at this point in the history
The codebase is now strict-null compliant and the CI checks will fail if a PR tries to introduce code that is not.
  • Loading branch information
petebacondarwin committed Jan 20, 2022
1 parent 1704d23 commit 5fcef05
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/quiet-pianos-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

refactor: enable TypeScript strict-null checks

The codebase is now strict-null compliant and the CI checks will fail if a PR tries to introduce code that is not.
4 changes: 3 additions & 1 deletion packages/wrangler/pages/functions/filepath-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export async function generateConfigFromFileTree({
export function compareRoutes(a: string, b: string) {
function parseRoutePath(routePath: string): [string | null, string[]] {
const parts = routePath.split(" ", 2);
const segmentedPath = parts.pop();
// split() will guarantee at least one element.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const segmentedPath = parts.pop()!;
const method = parts.pop() ?? null;

const segments = segmentedPath.slice(1).split("/").filter(Boolean);
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("Dev component", () => {
accountId: "some-account-id",
public: "some/public/path",
});
expect(lastFrame().split("\n").slice(0, 2).join("\n"))
expect(lastFrame()?.split("\n").slice(0, 2).join("\n"))
.toMatchInlineSnapshot(`
"Something went wrong:
Error: You cannot use the service worker format with a \`public\` directory."
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/cfetch/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function fetchInternal<ResponseType>(
}
}

function cloneHeaders(headers: HeadersInit): HeadersInit {
function cloneHeaders(headers: HeadersInit | undefined): HeadersInit {
return { ...headers };
}

Expand Down
12 changes: 8 additions & 4 deletions packages/wrangler/src/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,10 @@ function logConsoleMessage(evt: Protocol.Runtime.ConsoleAPICalledEvent): void {
case "map":
args.push(
"{\n" +
ro.preview.entries
.map(({ key, value }) => {
// Maps always have entries
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
ro.preview
.entries!.map(({ key, value }) => {
return ` ${key?.description ?? "<unknown>"} => ${
value.description
}`;
Expand All @@ -485,8 +487,10 @@ function logConsoleMessage(evt: Protocol.Runtime.ConsoleAPICalledEvent): void {
case "set":
args.push(
"{ " +
ro.preview.entries
.map(({ value }) => {
// Sets always have entries
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
ro.preview
.entries!.map(({ value }) => {
return `${value.description}`;
})
.join(", ") +
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ export default async function publish(props: Props): Promise<void> {
const entryPointExports = entryPoints[0].exports;
const resolvedEntryPointPath = path.resolve(
destination.path,
entryPoints[0].entryPoint
// We know that entryPoint is not null because we filtered out those without above.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
entryPoints[0].entryPoint!
);
const { format } = props;
const bundle = {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"lib": ["esnext"],
"jsx": "react",
"resolveJsonModule": true,
"incremental": true
"incremental": true,
"strictNullChecks": true
},
"exclude": ["node_modules/", "packages/*/vendor", "packages/*/*-dist"]
}

0 comments on commit 5fcef05

Please sign in to comment.