Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nasty-dogs-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

Updates the default Astro config with `// @ts-check` if the Typescript preset is `strict` or `strictest`
15 changes: 15 additions & 0 deletions packages/create-astro/src/actions/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down