import type { LocationQueryRaw } from '../query'
import type { MatcherName } from './matcher'
-// the matcher can serialize and deserialize params
+/**
+ * Generic object of params that can be passed to a matcher.
+ */
export type MatcherParamsFormatted = Record<string, unknown>
export interface MatcherLocationAsName {
query?: LocationQueryRaw
hash?: string
+ /**
+ * A path is ignored if `name` is provided.
+ */
path?: undefined
}
+/**
+ * NOTE: for these classes to keep the same code we need to tell TS with `"useDefineForClassFields": true` in the `tsconfig.json`
+ */
+
+/**
+ * Error throw when a matcher miss
+ */
export class MatchMiss extends Error {
name = 'MatchMiss'
}
+// NOTE: not sure about having a helper. Using `new MatchMiss(description?)` is good enough
export const miss = () => new MatchMiss()
+/**
+ * Error throw when a param is invalid when parsing params from path, query, or hash.
+ */
export class ParamInvalid extends Error {
name = 'ParamInvalid'
constructor(public param: string) {
"noImplicitReturns": true,
"strict": true,
"skipLibCheck": true,
+ "useDefineForClassFields": true,
// "noUncheckedIndexedAccess": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"removeComments": false,
"jsx": "preserve",
- "lib": [
- "esnext",
- "dom"
- ],
- "types": [
- "node",
- "vite/client"
- ]
+ "lib": ["esnext", "dom"],
+ "types": ["node", "vite/client"]
}
}