From 7514b7037a611a2bbd857bbb7de73220852eb86e Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 22 Sep 2026 09:08:37 -0400 Subject: [PATCH] fix: make secret-messages type-check at the project level `check-solutions.sh "tsc"` runs a bare `npm run tsc` in every project, which for secret-messages compiles both steps against the project-level TSConfig. That has failed since the project was added in #82, but the all-projects branch only runs when a PR touches no `projects/**` files, so it went unnoticed. `answer.js` and `guesses.json` need `allowJs` and `resolveJsonModule`, which exist only in the step's own TSConfig -- the file the reader fills in, and which a project-level `tsc` never reads. Adds them to the project TSConfig, with `noEmit` to avoid TS5055 overwriting `answer.js`. `message.codePointAt(i)` is typed `number | undefined`, so it needs a non-null assertion under `strict`. Switches both steps to `charCodeAt`, which returns `number` and pairs more naturally with `fromCharCode`. That also drops the `!` from `01-encoded-outputs`, which was the only non-null assertion in the repository -- worth avoiding in a chapter 13 project regardless. Output is unchanged: the two differ only for characters above the BMP, and these messages are ASCII. Co-Authored-By: Claude Opus 5 (1M context) --- .../secret-messages/01-encoded-outputs/index.ts | 2 +- .../secret-messages/02-allowed-imports/index.ts | 2 +- projects/configuration-options/secret-messages/tsconfig.json | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/projects/configuration-options/secret-messages/01-encoded-outputs/index.ts b/projects/configuration-options/secret-messages/01-encoded-outputs/index.ts index 5e31b6f2..5ffe2c80 100644 --- a/projects/configuration-options/secret-messages/01-encoded-outputs/index.ts +++ b/projects/configuration-options/secret-messages/01-encoded-outputs/index.ts @@ -4,7 +4,7 @@ export function encodeMessage(message: string) { let output = ""; for (let i = 0; i < message.length; i += 1) { - output += String.fromCharCode(message.codePointAt(i)! + i + message.length); + output += String.fromCharCode(message.charCodeAt(i) + i + message.length); } return output; diff --git a/projects/configuration-options/secret-messages/02-allowed-imports/index.ts b/projects/configuration-options/secret-messages/02-allowed-imports/index.ts index 134cd677..9d8d210c 100644 --- a/projects/configuration-options/secret-messages/02-allowed-imports/index.ts +++ b/projects/configuration-options/secret-messages/02-allowed-imports/index.ts @@ -5,7 +5,7 @@ export function decodeMessage(message: string) { let output = ""; for (let i = 0; i < message.length; i += 1) { - output += String.fromCharCode(message.codePointAt(i) - i - message.length); + output += String.fromCharCode(message.charCodeAt(i) - i - message.length); } return output; diff --git a/projects/configuration-options/secret-messages/tsconfig.json b/projects/configuration-options/secret-messages/tsconfig.json index 3fcafa94..8ee4191e 100644 --- a/projects/configuration-options/secret-messages/tsconfig.json +++ b/projects/configuration-options/secret-messages/tsconfig.json @@ -1,4 +1,9 @@ { + "compilerOptions": { + "allowJs": true, + "noEmit": true, + "resolveJsonModule": true + }, "extends": "../../../tsconfig.json", "include": ["."] }