chore: update types in tests, init, update (#2122)

Of particular note is the change to
`tests/fixture_plugin/routes/test.tsx`. Note how I do this:
```diff
-  async GET(_req, ctx: HandlerContext<unknown, { test: string }>) {
+  async GET(_req, ctx: FreshContext<{ test: string }, unknown>) {
```

I find it strange and confusing that the order of the type parameters
has "changed". This makes it impossible to do a simple search and
replace, because people now have to change order as well.

Most of the types have been declared as `<T, S>`, i.e. data before
state:
* `PageProps<T = any, S = Record<string, unknown>>`
* `RouteContext<T = any, S = Record<string, unknown>>`
* `Handler<T = any, State = Record<string, unknown>>`
* `Handlers<T = any, State = Record<string, unknown>> `
* `AsyncRoute<T = any, S = Record<string, unknown>>`
* `PageComponent<T = any, S = Record<string, unknown>> `
* `AsyncLayout<T = any, S = Record<string, unknown>>`

And then `FreshContext` comes around like 
```
export interface FreshContext<
  State = Record<string, unknown>,
  // deno-lint-ignore no-explicit-any
  Data = any,
  NotFoundData = Data,
>
```
and switches it all up.

Not a huge issue, but just something to be aware of that others might
report.
This commit is contained in:
Reed von Redwitz
2023-12-02 10:33:59 +01:00
committed by GitHub
parent 8fecfb940c
commit 35da45bff1
61 changed files with 128 additions and 137 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import { AppProps } from "$fresh/server.ts";
import { PageProps } from "$fresh/server.ts";
export default function App({ Component, state }: AppProps) {
export default function App({ Component, state }: PageProps) {
return (
<div class="app">
<Component />
+2 -2
View File
@@ -1,8 +1,8 @@
import { LayoutProps } from "$fresh/server.ts";
import { PageProps } from "$fresh/server.ts";
import { LayoutState } from "./_middleware.ts";
export default function RootLayout(
{ Component, state }: LayoutProps<unknown, LayoutState>,
{ Component, state }: PageProps<unknown, LayoutState>,
) {
return (
<div class="root-layout">
+2 -2
View File
@@ -1,4 +1,4 @@
import { MiddlewareHandlerContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
export type LayoutState = {
something: string;
@@ -6,7 +6,7 @@ export type LayoutState = {
export const handler = (
_req: Request,
ctx: MiddlewareHandlerContext<LayoutState>,
ctx: FreshContext<LayoutState>,
) => {
ctx.state.something = "it works";
return ctx.next();
@@ -1,9 +1,9 @@
import { LayoutContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
import { delay } from "$fresh/tests/deps.ts";
export default async function AsyncLayout(
req: Request,
ctx: LayoutContext,
ctx: FreshContext,
) {
await delay(10);
return (
@@ -1,9 +1,9 @@
import { LayoutContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
import { delay } from "$std/async/mod.ts";
export default async function AsyncSubLayout(
req: Request,
ctx: LayoutContext,
ctx: FreshContext,
) {
await delay(10);
return new Response(null, {
@@ -1,8 +1,8 @@
import { LayoutContext } from "$fresh/server.ts";
import { FreshContext } from "$fresh/server.ts";
export default async function AsyncSubLayout(
req: Request,
ctx: LayoutContext,
ctx: FreshContext,
) {
await new Promise((r) => setTimeout(r, 10));
return (
@@ -1,6 +1,6 @@
import { h } from "preact";
import { LayoutProps } from "$fresh/server.ts";
import { PageProps } from "$fresh/server.ts";
export default function TsLayout({ Component }: LayoutProps) {
export default function TsLayout({ Component }: PageProps) {
return h("div", { class: "ts-layout" }, h(Component, null));
}
@@ -1,7 +1,7 @@
import { h } from "preact";
import { LayoutProps } from "$fresh/server.ts";
import { PageProps } from "$fresh/server.ts";
export default function TsxLayout({ Component }: LayoutProps) {
export default function TsxLayout({ Component }: PageProps) {
return (
<div class="tsx-layout">
<Component />
+2 -2
View File
@@ -1,6 +1,6 @@
import { LayoutProps } from "$fresh/server.ts";
import { PageProps } from "$fresh/server.ts";
export default function FooLayout({ Component }: LayoutProps) {
export default function FooLayout({ Component }: PageProps) {
return (
<div class="foo-layout">
<Component />
@@ -1,10 +1,10 @@
import { LayoutConfig, LayoutProps } from "$fresh/server.ts";
import { LayoutConfig, PageProps } from "$fresh/server.ts";
export const config: LayoutConfig = {
skipInheritedLayouts: true,
};
export default function OverrideLayout({ Component }: LayoutProps) {
export default function OverrideLayout({ Component }: PageProps) {
return (
<div class="override-layout">
<Component />
@@ -1,10 +1,10 @@
import { LayoutConfig, LayoutProps } from "$fresh/server.ts";
import { LayoutConfig, PageProps } from "$fresh/server.ts";
export const config: LayoutConfig = {
skipAppWrapper: true,
};
export default function OverrideLayout({ Component }: LayoutProps) {
export default function OverrideLayout({ Component }: PageProps) {
return (
<div class="no-app-layout">
<Component />
@@ -1,6 +1,6 @@
import { LayoutProps } from "$fresh/server.ts";
import { PageProps } from "$fresh/server.ts";
export default function SubLayout({ Component }: LayoutProps) {
export default function SubLayout({ Component }: PageProps) {
return (
<div class="sub-layout">
<Component />