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

feat(types): RouterConfig for multiple components (#3217) #3218

Merged
merged 2 commits into from
Jun 4, 2020

Conversation

javiertury
Copy link
Contributor

@javiertury javiertury commented Jun 2, 2020

Closes #3217

The test demonstrates that with correct typings, typescript is able to infer that route is of type Route on its own.

             abc: route => route.params,

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

types/router.d.ts Outdated Show resolved Hide resolved
types/router.d.ts Outdated Show resolved Hide resolved
@javiertury javiertury force-pushed the routerconfig_types branch 3 times, most recently from 6d3cb0b to e462bb2 Compare June 3, 2020 15:04
@javiertury
Copy link
Contributor Author

Done

Copy link
Member

@posva posva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. Let me just move the children next to components as well and I will merge this

types/router.d.ts Outdated Show resolved Hide resolved
types/router.d.ts Show resolved Hide resolved
@posva posva merged commit dab86c5 into vuejs:dev Jun 4, 2020
@andersbc
Copy link

andersbc commented Jun 18, 2020

The associated commit broke my ts use case

I have a custom interface for my Router configuration, e.g.:

// file: routes.ts
// ...
import { RouteConfig } from 'vue-router'

interface MyRouteConfig extends RouteConfig {
  meta?: MyMeta; // <- defined elsewhere
}

export const routes: Array<MyRouteConfig> = [
  // ... the usual route configuration, with my added meta-thing
]

After the commit, the RouteConfig is now a union type, i.e.. RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews

However, typescript can't extend from union types, because "An interface can only extend an object type or intersection of object types with statically known members"

What I really need is to extends the new RouteConfigMultipleViews type, but it doesn't get exported. Any chance of exporting it? Thanks :-)

@javiertury
Copy link
Contributor Author

That was a case I missed.

They are trying to fix it in #3234. Personally I think that using a generic RouteConfig<Meta = any> as proposed in this comment is a good solution.

@posva
Copy link
Member

posva commented Jun 19, 2020

FYI, adding a generic to the type should go through an RFC because is not that simple of a change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accurate typings for Routeconfig: component, components, props
3 participants