test(docs): type check docs code examples (#3180)

This PR adds the initial seeds of type checking the code in all code
blocks for the Markdown Docs.

- Adds a unit test, disabled due to the many remaining errors, that can
help find incorrect code
- Fixes a bunch of syntax errors, type errors, and other code issues
found in the docs

## Future improvements

A lot of remaining issues is mostly related to missing imports, e.g.
`App`, `staticFiles`, `HttpError` etc. There's a couple of different
directions to solve this in future PR's.

- Add explicit imports to all docs examples (may become unnecessarily
verbose)
- Add code to docs code blocks, but with a hint to remove it when
rendering the markdown as HTML
   ```tsx
   import { App } from "fresh";
   // #docs-start

   // Everything above marker above is trimmed away
   const app = new App();
   ```
- Add a `types.d.ts` with "global" types used during type checking, so
globals, imports and so on can be handled globally

I do think that some examples probably should be more explicit with
imports, but it would be overkill for a lot of places such as `app.md`
and `context.md`.
This commit is contained in:
Christian Svensson
2025-08-05 23:56:04 +02:00
committed by GitHub
parent e014d80a0f
commit b7f1abb0d0
13 changed files with 142 additions and 24 deletions
+5 -1
View File
@@ -29,7 +29,7 @@ An island can be used anywhere like a regular Preact component. Fresh will take
care of making it interactive on the client.
```tsx main.tsx
import MyIsland from "../islands/my-island.tsx";
import MyIsland from "./islands/my-island.tsx";
const app = new App()
.get("/", (ctx) => ctx.render(<MyIsland />));
@@ -94,6 +94,10 @@ In essence, Fresh allows you to mix static and interactive parts in your app in
a way that's most optimal for your app. We'll keep sending only the JavaScript
that is needed for the islands to the browser.
```tsx islands/other-island.tsx
export default (props: { foo: string }) => <>{props.foo}</>;
```
```tsx route/index.tsx
import MyIsland from "../islands/my-island.tsx";
import OtherIsland from "../islands/other-island.tsx";