From ccae0e5358c36c11d2e4d34559c093040c5b112a Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Fri, 20 Sep 2024 15:39:27 +0200 Subject: [PATCH] feat: try type routePattern --- examples/blog/src/pages/index.astro | 2 ++ examples/blog/tsconfig.json | 2 +- packages/astro/src/types/public/context.ts | 4 ++-- packages/astro/src/types/public/extendables.ts | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/blog/src/pages/index.astro b/examples/blog/src/pages/index.astro index 31269efde0..4cf898436c 100644 --- a/examples/blog/src/pages/index.astro +++ b/examples/blog/src/pages/index.astro @@ -3,6 +3,8 @@ import BaseHead from '../components/BaseHead.astro'; import Header from '../components/Header.astro'; import Footer from '../components/Footer.astro'; import { SITE_TITLE, SITE_DESCRIPTION } from '../consts'; + +Astro.routePattern --- diff --git a/examples/blog/tsconfig.json b/examples/blog/tsconfig.json index 676d1945a1..0dc098dd7e 100644 --- a/examples/blog/tsconfig.json +++ b/examples/blog/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "astro/tsconfigs/base", + "extends": "astro/tsconfigs/strict", "include": [".astro/types.d.ts", "**/*"], "exclude": ["dist"], "compilerOptions": { diff --git a/packages/astro/src/types/public/context.ts b/packages/astro/src/types/public/context.ts index 8d7c4fb307..d1beead966 100644 --- a/packages/astro/src/types/public/context.ts +++ b/packages/astro/src/types/public/context.ts @@ -146,7 +146,7 @@ export interface AstroGlobal< * - The value when rendering `src/pages/blog/[slug].astro` will `blog/[slug]`. * - The value when rendering `src/pages/[...path].astro` will `[...path]`. */ - routePattern: string; + routePattern: keyof App.RoutePattern extends never ? string : keyof App.RoutePattern; /** * The element allows a component to reference itself recursively. * @@ -523,5 +523,5 @@ export interface APIContext< * - The value when rendering `src/pages/blog/[slug].astro` will `blog/[slug]`. * - The value when rendering `src/pages/[...path].astro` will `[...path]`. */ - routePattern: string; + routePattern: keyof App.RoutePattern extends never ? string : keyof App.RoutePattern; } diff --git a/packages/astro/src/types/public/extendables.ts b/packages/astro/src/types/public/extendables.ts index 1592eda190..23dc72c8b9 100644 --- a/packages/astro/src/types/public/extendables.ts +++ b/packages/astro/src/types/public/extendables.ts @@ -10,6 +10,7 @@ declare global { * Used by middlewares to store information, that can be read by the user via the global `Astro.locals` */ export interface Locals {} + export interface RoutePattern {} } namespace Astro {