Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface RouteConfig is not exported anymore #3234

Closed
Shinigami92 opened this issue Jun 16, 2020 · 5 comments
Closed

Interface RouteConfig is not exported anymore #3234

Shinigami92 opened this issue Jun 16, 2020 · 5 comments
Labels
Typescript Typescript related issues

Comments

@Shinigami92
Copy link

Version

3.3.3

Reproduction link

Please see Steps to reproduce below

Steps to reproduce

import { RouteConfig } from 'vue-router';
import RouteMetaInformation from './RouteMetaInformation';

/**
 * RouteConfig using RouteMetaInformation.
 */
export default interface RouteMetaConfig extends RouteConfig {
  meta?: RouteMetaInformation;
  children?: RouteMetaConfig[];
}

What is expected?

RouterConfig / RouterConfigBase should be exported so consumer can extends from it

https://github.com/vuejs/vue-router/blob/v3.3.2/types/router.d.ts#L92

What is actually happening?

_RouterConfigBase is not exported anymore

https://github.com/vuejs/vue-router/blob/v3.3.3/types/router.d.ts#L92

@posva
Copy link
Member

posva commented Jun 16, 2020

_RouteConfigBase is private but we can expose the two interface for multiple and single views: https://github.com/vuejs/vue-router/blob/v3.3.3/types/router.d.ts#L103-L112

@posva posva added the Typescript Typescript related issues label Jun 16, 2020
@Shinigami92
Copy link
Author

I think this could be helpful

So I can maybe do something like this:

export default interface RouteMetaConfigSingleView extends RouteConfigSingleView {
  meta?: RouteMetaInformation;
}

export default interface RouteMetaConfigMultipleViews extends RouteConfigMultipleViews {
  meta?: RouteMetaInformation;
  children?: RouteMetaConfig[];
}

export type RouteMetaConfig = RouteMetaConfigSingleView | RouteMetaConfigMultipleViews;

But maybe my problem is related to #3183
And therefore it could be helpful to have

interface _RouteConfigBase<Meta = any> {
  path: string
  name?: string
  redirect?: RedirectOption
  alias?: string | string[]
  meta?: Meta
  beforeEnter?: NavigationGuard
  caseSensitive?: boolean
  pathToRegexpOptions?: PathToRegexpOptions
}

export interface RouteConfigSingleView<Meta = any> extends _RouteConfigBase<Meta> {
  component?: Component
  props?: boolean | Object | RoutePropsFunction
}

export interface RouteConfigMultipleViews<Meta = any> extends _RouteConfigBase<Meta> {
  components?: Dictionary<Component>
  children?: RouteConfig[]
  props?: Dictionary<boolean | Object | RoutePropsFunction>
}

export type RouteConfig<Meta = any> = RouteConfigSingleView<Meta> | RouteConfigMultipleViews<Meta>

Problem with that: each meta would have applied the same interface. But maybe this is not a big problem when using optional properties.

e.g.

{ hideInNavi?: boolean, breadcrumb?: string }

@posva
Copy link
Member

posva commented Jun 19, 2020

Adding a generic to the type should go through an RFC because is not that simple of a change. If anybody is interested in leading that, please do at https://github.com/vuejs/rfcs. As noted, take into account what has been said at #3183

@Shinigami92
Copy link
Author

#3183 (comment) This idea could resolve my problem

@Shinigami92
Copy link
Author

Cause nothing has changed until now, I have rewritten my code as following:

import { RouteConfigMultipleViews, RouteConfigSingleView } from 'vue-router/types/router';
import RouteMetaInformation from './RouteMetaInformation';

export interface RouteMetaConfigSingleView extends RouteConfigSingleView {
  meta?: RouteMetaInformation;
  children?: RouteMetaConfig[];
}

export interface RouteMetaConfigMultipleViews extends RouteConfigMultipleViews {
  meta?: RouteMetaInformation;
  children?: RouteMetaConfig[];
}

/**
 * RouteConfig using RouteMetaInformation.
 */
export type RouteMetaConfig = RouteMetaConfigSingleView | RouteMetaConfigMultipleViews;

You can close this issue if you want

@posva posva closed this as completed Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typescript Typescript related issues
Projects
None yet
Development

No branches or pull requests

2 participants