]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(types): fix types for redirect records
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 11 Sep 2020 13:24:01 +0000 (15:24 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 11 Sep 2020 13:24:01 +0000 (15:24 +0200)
src/types/index.ts
test-dts/routeRecords.test-d.ts [new file with mode: 0644]

index f925caa9bed316e8a919a002354ad20e6b29c54f..77ad864bfdc6836846e11a130954728784c2fc7b 100644 (file)
@@ -237,6 +237,7 @@ export interface RouteRecordSingleView extends _RouteRecordBase {
    * Component to display when the URL matches this route.
    */
   component: RawRouteComponent
+  components?: never
   /**
    * Allow passing down params as props to the component rendered by `router-view`.
    */
@@ -251,6 +252,7 @@ export interface RouteRecordMultipleViews extends _RouteRecordBase {
    * Components to display when the URL matches this route. Allow using named views.
    */
   components: Record<string, RawRouteComponent>
+  component?: never
   /**
    * Allow passing down params as props to the component rendered by
    * `router-view`. Should be an object with the same keys as `components` or a
@@ -260,14 +262,13 @@ export interface RouteRecordMultipleViews extends _RouteRecordBase {
 }
 
 /**
- * Route Record that defines a redirect. Cannot have `component`, `components` or
- * `children` as it is never rendered.
+ * Route Record that defines a redirect. Cannot have `component` or `components`
+ * as it is never rendered.
  */
 export interface RouteRecordRedirect extends _RouteRecordBase {
   redirect: RouteRecordRedirectOption
   component?: never
   components?: never
-  children?: never
 }
 
 export type RouteRecordRaw =
diff --git a/test-dts/routeRecords.test-d.ts b/test-dts/routeRecords.test-d.ts
new file mode 100644 (file)
index 0000000..bcc59d9
--- /dev/null
@@ -0,0 +1,31 @@
+import { RouteRecordRaw } from './index'
+import { defineComponent } from 'vue'
+
+const component = defineComponent({})
+const components = { default: component }
+
+const routes: RouteRecordRaw[] = []
+
+routes.push({ path: '/', redirect: '/foo' })
+
+// @ts-expect-error cannot have components and component at the same time
+routes.push({ path: '/', components, component })
+
+routes.push({
+  path: '/',
+  redirect: '/foo',
+  children: [],
+})
+
+routes.push({ path: '/', component, props: true })
+routes.push({ path: '/', component, props: to => to.params.id })
+// @ts-expect-error: props should be an object
+routes.push({ path: '/', components, props: to => to.params.id })
+routes.push({ path: '/', components, props: { default: to => to.params.id } })
+routes.push({ path: '/', components, props: true })
+
+// let r: RouteRecordRaw = {
+//   path: '/',
+//   component,
+//   components,
+// }