Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/router/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface RouteRecordViewLoose extends Pick<
enterCallbacks: Record<string, Function[]>
props: Record<string, _RouteRecordProps>
aliasOf: RouteRecordNormalized | RouteRecordViewLoose | undefined
children?: RouteRecordRaw[]
children?: RouteRecordRaw[] | undefined
components: Record<string, RouteComponent> | null | undefined
}

Expand All @@ -67,7 +67,7 @@ export interface RouteLocationNormalizedLoose extends RouteLocationNormalized {
path: string
// record?
params: any
redirectedFrom?: Partial<MatcherLocation>
redirectedFrom?: Partial<MatcherLocation> | undefined
meta: any
matched: Partial<RouteRecordViewLoose>[]
}
Expand All @@ -77,7 +77,7 @@ export interface MatcherLocationNormalizedLoose {
path: string
// record?
params: any
redirectedFrom?: Partial<MatcherLocation>
redirectedFrom?: Partial<MatcherLocation> | undefined
meta: any
matched: Partial<RouteRecordViewLoose>[]
instances: Record<string, any>
Expand Down
50 changes: 50 additions & 0 deletions packages/router/src/exactOptionalPropertyTypes.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, it, expectTypeOf } from 'vitest'
import type {
ScrollPositionCoordinates,
_ScrollPositionNormalized,
} from './scrollBehavior'
import type { _RouteRecordBase } from './types'
import type { ResolvedOptions } from './unplugin/options'

describe('exactOptionalPropertyTypes', () => {
it('ScrollPositionCoordinates accepts valid values', () => {
expectTypeOf<ScrollPositionCoordinates>().toEqualTypeOf<{
behavior?: ScrollBehavior
left?: number
top?: number
}>()
})

it('_ScrollPositionNormalized accepts explicit undefined for behavior', () => {
// behavior includes | undefined because savedPosition.behavior
// can be absent at runtime (e.g. computeScrollPosition omits it)
const pos: _ScrollPositionNormalized = {
behavior: undefined,
left: 0,
top: 0,
}
void pos
})

it('_RouteRecordBase meta does not allow undefined', () => {
expectTypeOf<_RouteRecordBase['meta']>().not.toEqualTypeOf<undefined>()
})

it('ResolvedOptions has non-nullable extensions after resolveOptions', () => {
expectTypeOf<ResolvedOptions['extensions']>().toEqualTypeOf<string[]>()
})

it('ResolvedOptions has non-nullable root after resolveOptions', () => {
expectTypeOf<ResolvedOptions['root']>().toEqualTypeOf<string>()
})

it('ResolvedOptions has non-nullable getRouteName after resolveOptions', () => {
expectTypeOf<
ResolvedOptions['getRouteName']
>().not.toEqualTypeOf<undefined>()
})

it('ResolvedOptions has non-nullable dts after resolveOptions', () => {
expectTypeOf<ResolvedOptions['dts']>().not.toEqualTypeOf<undefined>()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface AutoExportLoadersOptions {
* Root of the project. All paths are resolved relatively to this one.
* @default `process.cwd()`
*/
root?: string
root?: string | undefined
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
import { useRoute, useRouter } from '../../useApi'
import type { Router } from '../../router'
import type { LocationQuery } from '../../query'
import type { RouteParamsGeneric } from '../../types'

/**
* Creates a Pinia Colada data loader with `data` is always defined.
Expand Down Expand Up @@ -729,7 +730,7 @@ export interface DataLoaderColadaEntry<

interface TrackedRoute {
ready: boolean
params: Partial<LocationQuery>
params: Partial<RouteParamsGeneric>
query: Partial<LocationQuery>
hash: { v: string | null }
}
Expand Down
9 changes: 4 additions & 5 deletions packages/router/src/experimental/data-loaders/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { LocationQuery } from '../../query'
import { Router } from '../../router'
import { RouteLocationNormalizedLoaded } from '../../typed-routes'
import type { DataLoaderEntryBase, UseDataLoader } from './createDataLoader'
Expand Down Expand Up @@ -113,10 +112,10 @@ function trackObjectReads<T extends Record<string, unknown>>(obj: T) {
* @param outer - the bigger params
* @param inner - the smaller params
*/
export function isSubsetOf(
inner: Partial<LocationQuery>,
outer: LocationQuery
): boolean {
export function isSubsetOf<
V extends string | null | undefined,
T extends Record<string, V | V[]>,
>(inner: Partial<T>, outer: T): boolean {
for (const key in inner) {
const innerValue = inner[key]
const outerValue = outer[key]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ export interface EXPERIMENTAL_ResolverRecord_Base {
* Name of the matcher. Unique across all matchers. If missing, this record
* cannot be matched. This is useful for grouping records.
*/
name?: RecordName
name?: RecordName | undefined

/**
* {@link MatcherPattern} for the path section of the URI.
*/
path?: MatcherPatternPath
path?: MatcherPatternPath | undefined

/**
* {@link MatcherPattern} for the query section of the URI.
*/
query?: MatcherPatternQuery[]
query?: MatcherPatternQuery[] | undefined

/**
* {@link MatcherPattern} for the hash section of the URI.
*/
hash?: MatcherPatternHash
hash?: MatcherPatternHash | undefined

/**
* Parent record. The parent can be a group or a matchable record.
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export interface LocationNormalized {
*/
interface LocationPartial {
path: string
query?: LocationQueryRaw
hash?: string
query?: LocationQueryRaw | undefined
hash?: string | undefined
}

const TRAILING_SLASH_RE = /\/$/
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/matcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function pickParams(
* @returns the normalized version
*/
export function normalizeRouteRecord(
record: RouteRecordRaw & { aliasOf?: RouteRecordNormalized }
record: RouteRecordRaw & { aliasOf?: RouteRecordNormalized | undefined }
): RouteRecordNormalized {
const normalized: Omit<RouteRecordNormalized, 'mods'> = {
path: record.path,
Expand Down
8 changes: 4 additions & 4 deletions packages/router/src/matcher/pathParserRanker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ export interface _PathParserOptions {
*
* @defaultValue `false`
*/
sensitive?: boolean
sensitive?: boolean | undefined

/**
* Whether to disallow a trailing slash or not.
*
* @defaultValue `false`
*/
strict?: boolean
strict?: boolean | undefined

/**
* Should the RegExp match from the beginning by prepending a `^` to it.
* @internal
*
* @defaultValue `true`
*/
start?: boolean
start?: boolean | undefined

/**
* Should the RegExp match until the end by appending a `$` to it.
Expand All @@ -80,7 +80,7 @@ export interface _PathParserOptions {
*
* @defaultValue `true`
*/
end?: boolean
end?: boolean | undefined
}

export type PathParserOptions = Pick<
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/scrollBehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { warn } from './warning'
* Note that not all browsers support `behavior`.
*/
export type ScrollPositionCoordinates = {
behavior?: ScrollOptions['behavior']
behavior?: ScrollOptions['behavior'] | undefined
left?: number
top?: number
}
Expand All @@ -24,7 +24,7 @@ export type ScrollPositionCoordinates = {
* @internal
*/
export type _ScrollPositionNormalized = {
behavior?: ScrollOptions['behavior']
behavior?: ScrollOptions['behavior'] | undefined
left: number
top: number
}
Expand Down
4 changes: 2 additions & 2 deletions packages/router/src/typed-routes/route-location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export type RouteLocationNormalizedLoadedTypedList<
*/
export interface RouteLocationAsRelativeGeneric
extends RouteQueryAndHash, RouteLocationOptions {
name?: RouteRecordNameGeneric
params?: RouteParamsRawGeneric
name?: RouteRecordNameGeneric | undefined
params?: RouteParamsRawGeneric | undefined
/**
* A relative path to the current location. This property should be removed
*/
Expand Down
7 changes: 4 additions & 3 deletions packages/router/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ export interface RouteLocationOptions {
* Note this will also add a new entry to the history unless `replace: true`
* is passed.
*/
force?: boolean
force?: boolean | undefined
/**
* State to save using the History API. This cannot contain any reactive
* values and some primitives like Symbols are forbidden. More info at
* https://developer.mozilla.org/en-US/docs/Web/API/History/state
*/
state?: HistoryState
state?: HistoryState | undefined
}

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ export interface _RouteRecordBase extends PathParserOptions {
* before any navigation guard and triggers a new navigation with the new
* target location.
*/
redirect?: RouteRecordRedirectOption
redirect?: RouteRecordRedirectOption | undefined

/**
* Aliases for the record. Allows defining extra paths that will behave like a
Expand All @@ -222,6 +222,7 @@ export interface _RouteRecordBase extends PathParserOptions {
beforeEnter?:
| NavigationGuardWithThis<undefined>
| NavigationGuardWithThis<undefined>[]
| undefined

/**
* Arbitrary data attached to the record.
Expand Down
14 changes: 9 additions & 5 deletions packages/router/src/unplugin/core/customBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ export interface CustomRouteBlock extends Partial<
> {
name?: string | undefined | false

alias?: string[]
alias?: string[] | undefined

params?: {
path?: Record<string, string>
params?:
| {
path?: Record<string, string> | undefined

query?: Record<string, string | CustomRouteBlockQueryParamOptions>
}
query?:
| Record<string, string | CustomRouteBlockQueryParamOptions>
| undefined
}
| undefined
}

export interface CustomRouteBlockQueryParamOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/router/src/unplugin/core/definePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ type DefinePageParamsInfo = NonNullable<CustomRouteBlock['params']>
export interface DefinePageInfo {
name?: string | false
path?: string
alias?: string[]
alias?: string[] | undefined
params?: CustomRouteBlock['params']
/**
* Whether definePage has properties beyond the statically extracted ones
Expand Down
18 changes: 11 additions & 7 deletions packages/router/src/unplugin/core/treeNodeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ export interface RouteRecordOverride extends Partial<
/**
* Path aliases.
*/
alias?: string[]
alias?: string[] | undefined

/**
* Param Parsers information.
*/
params?: {
path?: Record<string, string>
params?:
| {
path?: Record<string, string> | undefined

query?: Record<string, string | RouteRecordOverrideQueryParamOptions>
}
query?:
| Record<string, string | RouteRecordOverrideQueryParamOptions>
| undefined
}
| undefined
}

export interface RouteRecordOverrideQueryParamOptions extends CustomRouteBlockQueryParamOptions {
Expand Down Expand Up @@ -334,14 +338,14 @@ export interface TreeQueryParam {
/**
* Expression to be passed as is to the default value of the param.
*/
defaultValue?: string
defaultValue?: string | undefined

/**
* Whether the query param is required.
*
* @default false
*/
required?: boolean
required?: boolean | undefined
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/router/src/unplugin/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ export interface RoutesFolderOption {
* Allows to override the global `filePattern` option for this folder. It can also extend the global values by passing
* a function that returns an array.
*/
filePatterns?: _OverridableOption<string[], string | string[]>
filePatterns?: _OverridableOption<string[], string | string[]> | undefined

/**
* Allows to override the global `exclude` option for this folder. It can
* also extend the global values by passing a function that returns an array.
*/
exclude?: _OverridableOption<string[], string | string[]>
exclude?: _OverridableOption<string[], string | string[]> | undefined

/**
* Allows to override the global `extensions` option for this folder. It can
Expand Down Expand Up @@ -242,13 +242,13 @@ export interface Options {
* the backslash) to automatically re export any imported variable from files in the `src/loaders` folder within a
* page component.
*/
autoExportsDataLoaders?: string | string[]
autoExportsDataLoaders?: string | string[] | undefined

/**
* Enable experimental support for the new custom resolvers and allows
* defining custom param matchers.
*/
paramParsers?: boolean | ParamParsersOptions
paramParsers?: boolean | ParamParsersOptions | undefined
}
}

Expand Down
Loading