Skip to content

Commit 4e6c4e3

Browse files
fix(vue): support more complex types for routerLink
1 parent 8478be6 commit 4e6c4e3

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

example-project/vue-app-broken/src/App.vue

+18
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,23 @@ import { MyComponent, MyButton } from 'component-library-vue'
77
kidsNames="John"
88
/>
99
<my-button fill="ups">Button</my-button>
10+
<my-button :router-link="{name: 'user', para__ms: {username: 'cindy'}}"></my-button>
11+
12+
<!-- passing types -->
1013
<my-button router-link="/">Button</my-button>
14+
<my-button router-link="/about">
15+
About
16+
</my-button>
17+
<my-button :router-link="{name: 'user', params: {username: 'cindy'}}">
18+
Cindy
19+
</my-button>
20+
<my-button :router-link="{name: 'about'}">
21+
About
22+
</my-button>
23+
<my-button :router-link="{path: '/search', query: {id: 42}}">
24+
Search for 42
25+
</my-button>
26+
<my-button expand="full" :router-link="{name: 'about', hash: '#history'}">
27+
Our History
28+
</my-button>
1129
</template>

example-project/vue-app-broken/tests/type.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('type check', () => {
3131
[
3232
"src/App.vue(7,5): error TS2322: Type 'string' is not assignable to type 'string[]'.",
3333
"src/App.vue(9,14): error TS2322: Type '"ups"' is not assignable to type '"clear" | "outline" | "solid" | "default" | undefined'.",
34+
"src/App.vue(10,43): error TS2353: Object literal may only specify known properties, and 'para__ms' does not exist in type 'Symbol | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric'.",
3435
]
3536
`)
3637
})

packages/vue/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@
4848
},
4949
"peerDependencies": {
5050
"vue": "^3.4.38",
51+
"vue-router": "^4.5.0",
5152
"@stencil/core": ">=2.0.0 || >=3 || >= 4.0.0-beta.0 || >= 4.0.0"
5253
},
5354
"peerDependenciesMeta": {
5455
"vue": {
5556
"optional": false
5657
},
58+
"vue-router": {
59+
"optional": true
60+
},
5761
"@stencil/core": {
5862
"optional": true
5963
}
@@ -65,6 +69,7 @@
6569
"rimraf": "^5.0.0",
6670
"rollup": "^4.14.3",
6771
"typescript": "~5.7.0",
68-
"vitest": "^3.0.8"
72+
"vitest": "^3.0.8",
73+
"vue-router": "^4.5.0"
6974
}
7075
}

packages/vue/src/types.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { DefineSetupFnComponent } from 'vue';
1+
import type { DefineSetupFnComponent, VNodeProps, AllowedComponentProps, ComponentCustomProps } from 'vue';
2+
import type { RouteLocationAsRelativeGeneric, RouteLocationAsPathGeneric } from 'vue-router';
23

34
/**
45
* Options for the Vue Output Target
@@ -83,11 +84,11 @@ declare global {
8384
}
8485

8586
export type StencilVueComponent<Props, VModelType = string | number | boolean> = DefineSetupFnComponent<
86-
Props & InputProps<VModelType>,
87+
Props & InputProps<VModelType> & VNodeProps & AllowedComponentProps & ComponentCustomProps,
8788
{},
8889
{},
89-
Props & InputProps<VModelType>
90-
>;
90+
Props & InputProps<VModelType> & VNodeProps & AllowedComponentProps & ComponentCustomProps
91+
>
9192
export interface InputProps<T> {
9293
modelValue?: T;
9394
/**
@@ -99,5 +100,5 @@ export interface InputProps<T> {
99100
* For more information
100101
* @see https://ionicframework.com/docs/vue/navigation#navigating-using-router-link
101102
*/
102-
routerLink?: string | Symbol;
103+
routerLink?: Symbol | string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric;
103104
}

pnpm-lock.yaml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)