Skip to content

Instantly share code, notes, and snippets.

@BlueBazze
Created June 3, 2024 21:45
Show Gist options
  • Save BlueBazze/61cd0403a8eb3a5d0b6a7269669e999d to your computer and use it in GitHub Desktop.
Save BlueBazze/61cd0403a8eb3a5d0b6a7269669e999d to your computer and use it in GitHub Desktop.
// @ts-nocheck
// eslint-disable
// ---------------------------------------------------
// 🚗🚦 Generated by nuxt-typed-router. Do not modify !
// ---------------------------------------------------
export type RoutePathSchema =
"/"|"/en"|"/zh"
;
export type LocaleRoutePathSchema =
"/"
type ValidStringPath<T> = T extends `${string} ${string}` ? false : T extends '' ? false : true;
type ValidParam<T, R extends boolean = true> = T extends `${infer A}/${infer B}`
? A extends `${string} ${string}`
? false
: A extends `?${string}`
? false
: A extends `${string} ${string}`
? false
: A extends ''
? B extends ''
? true
: false
: B extends `?${string}`
? false
: B extends `#${string}`
? true
: B extends ''
? true
: false
: R extends true
? T extends ''
? false
: ValidParam<T, false>
: T extends `?${string}`
? false
: T extends `${string} ${string}`
? false
: true;
type ValidEndOfPath<T> = T extends `/`
? true
: T extends ''
? true
: T extends `${string} ${string}`
? false
: T extends `?${string}`
? true
: T extends `#${string}`
? true
: false;
type ValidateEn<T> = T extends `/en${infer TEn}`
? ValidEndOfPath<TEn> extends false ? "End of path '/en' is invalid" : true : false ;
type ValidateZh<T> = T extends `/zh${infer TZh}`
? ValidEndOfPath<TZh> extends false ? "End of path '/zh' is invalid" : true : false ;
export type ValidatePath<T extends string> = T extends string
? T extends '/'
? T
:ValidateEn<T> extends true ? T: ValidateZh<T> extends true ? T
: string extends T
? T
: `Error: ${ValidateEn<T>|ValidateZh<T>}`
: never;
// RouteNameFromPath, RouteNameFromLocalePath
export type RouteNameFromPath<T extends string> = T extends string
? T extends '/'
? "index"
: any : never
: never;
export type ValidateLocalePath<T extends string> = T extends string
? T extends '/'
? T
: string extends T
? T
: never
: never;
// RouteNameFromPath, RouteNameFromLocalePath
export type RouteNameFromLocalePath<T extends string> = T extends string
? T extends '/'
? "index"
: never
: never;
export type TypedPathParameter<T extends string> = ValidatePath<T> | RoutePathSchema;
export type TypedLocalePathParameter<T extends string> = ValidateLocalePath<T> | LocaleRoutePathSchema;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment