Skip to content

Commit

Permalink
fix(types): revert stricter meta
Browse files Browse the repository at this point in the history
Close #2319
  • Loading branch information
posva committed Aug 1, 2024
1 parent 5fef441 commit d4d0087
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 40 deletions.
1 change: 0 additions & 1 deletion packages/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export type {
RouteRecordMultipleViewsWithChildren,
RouteRecordRedirect,
RouteMeta,
_RouteMetaBase,
RouteComponent,
// RawRouteComponent,
RouteParamsGeneric,
Expand Down
40 changes: 3 additions & 37 deletions packages/router/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -230,7 +228,7 @@ export interface _RouteRecordBase
/**
* Arbitrary data attached to the record.
*/
// meta?: RouteMeta
meta?: RouteMeta

/**
* Array of nested routes.
Expand All @@ -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.
*
Expand All @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions packages/router/test-dts/meta.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand All @@ -28,6 +27,12 @@ describe('RouteMeta', () => {
},
},
},
{
path: '/hey',
component,
// @ts-expect-error: meta is missing `nested`
meta: {},
},
],
})

Expand Down

0 comments on commit d4d0087

Please sign in to comment.