]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(types): revert stricter meta
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 1 Aug 2024 07:57:37 +0000 (09:57 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 1 Aug 2024 07:57:43 +0000 (09:57 +0200)
Close #2319

packages/router/src/index.ts
packages/router/src/types/index.ts
packages/router/test-dts/meta.test-d.ts

index 089cfe0a7e9586d04990632fe69bc57eb457d42c..2a62ad15670c4d4f21d863a81b4cf2cace137422 100644 (file)
@@ -59,7 +59,6 @@ export type {
   RouteRecordMultipleViewsWithChildren,
   RouteRecordRedirect,
   RouteMeta,
-  _RouteMetaBase,
   RouteComponent,
   // RawRouteComponent,
   RouteParamsGeneric,
index 3508f3a6cf19bd397c5771c80d29c05379e53a32..e3069740b0d806c03ed97060c2b5d191e2730485 100644 (file)
@@ -189,9 +189,7 @@ export type RawRouteComponent = RouteComponent | Lazy<RouteComponent>
 /**
  * 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<string, _RouteRecordProps>
 }
 
-/**
- * Default type for RouteMeta when not augmented.
- * @internal
- */
-export type _RouteMetaBase = Record<string | number | symbol, unknown>
-
 /**
  * Interface to type `meta` fields in route records.
  *
@@ -265,33 +257,7 @@ export type _RouteMetaBase = Record<string | number | symbol, unknown>
  *  }
  * ```
  */
-export interface RouteMeta extends _RouteMetaBase {}
-
-/**
- * Returns `true` if the passed `RouteMeta` type hasn't been augmented. Return `false` otherwise.
- * @internal
- */
-export type IsRouteMetaBase<RM> = _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<RM> = Partial<RM> extends RM ? false : true
-
-export type _RouteRecordBaseMeta = IsRouteMetaRequired<RouteMeta> 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<string | number | symbol, unknown> {}
 
 /**
  * Route Record defining one single component with the `component` option.
index 95aa46101dee76032046cc7e7d46661554792b24..33bd677e12ba9912c810305416f82e6723d13f63 100644 (file)
@@ -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: {},
+        },
       ],
     })