I have a composable function that returns an array of objects and a function that received a string and doesn't return anything.
The below code 'works' and doesn't throw any errors.
import { ref } from "vue";
import { useRoute } from "vue-router";
interface RouterHelper {
children: any;
getChildrenOf: (name: string) => void;
}
export const routerHelper = (): RouterHelper => {
const route = useRoute();
const children = ref();
const getChildrenOf = (name: string) => {
children.value = route?.matched
?.find((r) => r.name === name)
?.children.filter((c) => c.alias);
};
return { children, getChildrenOf };
};
However, it isn't entirely accurate. For example, when declaring the children ref, it should be :
const children = ref([]);
But I get this error:
TS2322: Type 'RouteRecordRaw[] | undefined' is not assignable to type 'never[]'.
Also, in the interface, I have to use any instead of the proper type of [] for the children property.
Please note, I'm very new to Typescript, so when I say 'proper' take it with a grain of salt.
Any way I can make this code better and not use catch all's like any?
Thank you!