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:
+3
-12
@@ -1,16 +1,7 @@
|
||||
import { PARTIAL_SEARCH_PARAM } from "../constants.ts";
|
||||
import {
|
||||
BaseRoute,
|
||||
ErrorHandlerContext,
|
||||
FreshContext,
|
||||
ServeHandlerInfo,
|
||||
} from "./types.ts";
|
||||
import { BaseRoute, FreshContext } from "./types.ts";
|
||||
import { isIdentifierChar, isIdentifierStart } from "./init_safe_deps.ts";
|
||||
|
||||
type HandlerContext<T = unknown> = T & ServeHandlerInfo & {
|
||||
isPartial: boolean;
|
||||
};
|
||||
|
||||
export type Handler<T = Record<string, unknown>> = (
|
||||
req: Request,
|
||||
ctx: FreshContext<T>,
|
||||
@@ -91,7 +82,7 @@ export function defaultOtherHandler(_req: Request): Response {
|
||||
|
||||
export function defaultErrorHandler(
|
||||
_req: Request,
|
||||
_ctx: ErrorHandlerContext,
|
||||
_ctx: FreshContext,
|
||||
err: unknown,
|
||||
): Response {
|
||||
console.error(err);
|
||||
@@ -103,7 +94,7 @@ export function defaultErrorHandler(
|
||||
|
||||
export function defaultUnknownMethodHandler(
|
||||
_req: Request,
|
||||
_ctx: HandlerContext,
|
||||
_ctx: FreshContext,
|
||||
knownMethods: KnownMethod[],
|
||||
): Response {
|
||||
return new Response(null, {
|
||||
|
||||
Reference in New Issue
Block a user