Skip to content

Commit

Permalink
fix(types): fix types for redirect records
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 11, 2020
1 parent adde4c2 commit a77f148
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*/
Expand All @@ -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
Expand All @@ -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 =
Expand Down
31 changes: 31 additions & 0 deletions test-dts/routeRecords.test-d.ts
Original file line number Diff line number Diff line change
@@ -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,
// }

0 comments on commit a77f148

Please sign in to comment.