From d4d0087eae5721f73bde445be33407875a92a1ca Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 1 Aug 2024 09:57:37 +0200 Subject: [PATCH] fix(types): revert stricter meta Close #2319 --- packages/router/src/index.ts | 1 - packages/router/src/types/index.ts | 40 ++----------------------- packages/router/test-dts/meta.test-d.ts | 9 ++++-- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/packages/router/src/index.ts b/packages/router/src/index.ts index 089cfe0a7..2a62ad156 100644 --- a/packages/router/src/index.ts +++ b/packages/router/src/index.ts @@ -59,7 +59,6 @@ export type { RouteRecordMultipleViewsWithChildren, RouteRecordRedirect, RouteMeta, - _RouteMetaBase, RouteComponent, // RawRouteComponent, RouteParamsGeneric, diff --git a/packages/router/src/types/index.ts b/packages/router/src/types/index.ts index 3508f3a6c..e3069740b 100644 --- a/packages/router/src/types/index.ts +++ b/packages/router/src/types/index.ts @@ -189,9 +189,7 @@ export type RawRouteComponent = RouteComponent | Lazy /** * Internal type for common properties among all kind of {@link RouteRecordRaw}. */ -export interface _RouteRecordBase - extends PathParserOptions, - _RouteRecordBaseMeta { +export interface _RouteRecordBase extends PathParserOptions { /** * Path of the record. Should start with `/` unless the record is the child of * another record. @@ -230,7 +228,7 @@ export interface _RouteRecordBase /** * Arbitrary data attached to the record. */ - // meta?: RouteMeta + meta?: RouteMeta /** * Array of nested routes. @@ -243,12 +241,6 @@ export interface _RouteRecordBase props?: _RouteRecordProps | Record } -/** - * Default type for RouteMeta when not augmented. - * @internal - */ -export type _RouteMetaBase = Record - /** * Interface to type `meta` fields in route records. * @@ -265,33 +257,7 @@ export type _RouteMetaBase = Record * } * ``` */ -export interface RouteMeta extends _RouteMetaBase {} - -/** - * Returns `true` if the passed `RouteMeta` type hasn't been augmented. Return `false` otherwise. - * @internal - */ -export type IsRouteMetaBase = _RouteMetaBase extends RM ? true : false -/** - * Returns `true` if the passed `RouteMeta` type has been augmented with required fields. Return `false` otherwise. - * @internal - */ -export type IsRouteMetaRequired = Partial extends RM ? false : true - -export type _RouteRecordBaseMeta = IsRouteMetaRequired extends true - ? { - /** - * Arbitrary data attached to the record. Required because the `RouteMeta` type has been augmented with required - * fields. - */ - meta: RouteMeta - } - : { - /** - * Arbitrary data attached to the record. - */ - meta?: RouteMeta - } +export interface RouteMeta extends Record {} /** * Route Record defining one single component with the `component` option. diff --git a/packages/router/test-dts/meta.test-d.ts b/packages/router/test-dts/meta.test-d.ts index 95aa46101..33bd677e1 100644 --- a/packages/router/test-dts/meta.test-d.ts +++ b/packages/router/test-dts/meta.test-d.ts @@ -7,8 +7,7 @@ const component = defineComponent({}) declare module '.' { interface RouteMeta { requiresAuth?: boolean - // TODO: it would be nice to be able to test required meta without polluting all tests - nested?: { foo: string } + nested: { foo: string } } } @@ -28,6 +27,12 @@ describe('RouteMeta', () => { }, }, }, + { + path: '/hey', + component, + // @ts-expect-error: meta is missing `nested` + meta: {}, + }, ], })