-
Reading the new docs I'm a bit curious about the best way to use route placeholders. How to declare them, how to use them in the client, how to get them to play nice with typescript, etc. My use case is we'd like our api to have both For all my examples though I'm just using the one in the docs since it's nice and simple. From the docs it says you can do
Question 1First off I have a question about how I should pass the // Option a
client.service('messages').create('my message', {route:{userId:3}})
// Option b
client.service('3/messages').create('my message') Question 2I have a problem with how the types are created and used (both in the server and the feathers client that can be used elsewhere). Basically if my Option 1: Route placeholder in the service pathI want to use app.use(':userId/messages', new MessageService(getOptions(app), {}) but typescript doesn't like that unless I register it in the declarations the same way. declare module '../declarations' {
interface ServiceTypes {
':userId/messages': MessageTypes;
}
} Now everything works, but using the client is weird. const client = getClient(transport)
client.service('messages') // <== typescript throws an error
client.service(':userId/messages') // <== typescript is fine but this is a bit weird Option 2: Declare both servicesJust like option 1 but in the services declaration it would be declare module '../declarations' {
interface ServiceTypes {
':userId/messages': MessageTypes;
'messages': MessageTypes;
}
} which would tell typescript to allow the client to be used with However, due to the two options that typescript allows, I'm curious about how I could run into trouble in the feathers app itself. Lets say in my feathers app I now call Option 3: something elseIn the example I could just put the SummaryOverall just wanted to get an answer to my question about how to use the route placeholder when calling a service and then see if you had any insights about how to deal with those typescript problems that each option brought up (or not if that's just how it is dealing with typescript). Thanks for all the great stuff y'all are doing, this is a great project and I'm really excited about the schemas and typescript support that's coming with dove. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
I think part of the issue is that there is an inconsistency between using placeholders on the client vs. the server. I'm not even sure if the placeholder would work on the client but you can definitely do const client = getClient(transport)
client.service('3/messages') The problem is that this can't be typed other than import type { Service } from '@feathersjs/feathers'
declare module '../declarations' {
interface ServiceTypes {
[key: string]: Service;
}
} Since this is really a TypeScript limitation I don't think there is much that can be done here other than keeping things flat like suggested in the FAQ. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the info, it does seem like we're doing something a bit off with the non-flat route, I'll look into some other options |
Beta Was this translation helpful? Give feedback.
I think part of the issue is that there is an inconsistency between using placeholders on the client vs. the server. I'm not even sure if the placeholder would work on the client but you can definitely do
The problem is that this can't be typed other than
Since this is really a TypeScript limitation I don't think there is much that can be done here other than keeping things flat like suggested in the FAQ.