summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/nasty-dogs-sort.md5
-rw-r--r--packages/create-astro/src/actions/typescript.ts15
2 files changed, 20 insertions, 0 deletions
diff --git a/.changeset/nasty-dogs-sort.md b/.changeset/nasty-dogs-sort.md
new file mode 100644
index 000000000..225012a70
--- /dev/null
+++ b/.changeset/nasty-dogs-sort.md
@@ -0,0 +1,5 @@
+---
+'create-astro': patch
+---
+
+Updates the default Astro config with `// @ts-check` if the Typescript preset is `strict` or `strictest`
diff --git a/packages/create-astro/src/actions/typescript.ts b/packages/create-astro/src/actions/typescript.ts
index c0034fe4f..169aef708 100644
--- a/packages/create-astro/src/actions/typescript.ts
+++ b/packages/create-astro/src/actions/typescript.ts
@@ -140,6 +140,21 @@ const FILES_TO_UPDATE = {
}
}
},
+ 'astro.config.mjs': async (file: string, options: { value: string }) => {
+ if (!(options.value === 'strict' || options.value === 'strictest')) {
+ return;
+ }
+
+ try {
+ let data = await readFile(file, { encoding: 'utf-8' });
+ data = `// @ts-check\n${data}`;
+ await writeFile(file, data, { encoding: 'utf-8' });
+ } catch (err) {
+ // if there's no astro.config.mjs (which is very unlikely), then do nothing
+ if (err && (err as any).code === 'ENOENT') return;
+ if (err instanceof Error) throw new Error(err.message);
+ }
+ },
};
export async function setupTypeScript(value: string, ctx: PickedTypeScriptContext) {