-
-
Notifications
You must be signed in to change notification settings - Fork 797
Description
Hi,
By default, when generating a new service (Post) using feathers-cli will result in this interface declaration.
// Add this service to the service type index
declare module '../../declarations' {
interface ServiceTypes {
'post': Post & ServiceAddons<any>;
}
}Doing so, will not give us the overload type that is defined.. so we lose the overload methods declaration..
Made a small tweak to include interface for it, to illustrate it better
interface PostInterface {
title: string;
message: string;
}
// Add this service to the service type index
declare module '../../declarations' {
interface ServiceTypes {
'post': Post & ServiceAddons<PostInterface>;
}
}Notice that, it does not provide the overload methods by default as shown in the image above.
Now, if we were to declare as such..
// Add this service to the service type index
declare module '../../declarations' {
interface ServiceTypes {
'post': Post & ServiceOverloads<PostInterface> & ServiceAddons<PostInterface>;
}
}IDE will be able to pick up the correct overload types and display as such (shown in the image above)
So I thought that the default, should as such instead of Post & ServiceAddons<PostInterface>
To add-on, I'm not sure if there's actually any difference between declaring
// this
declare module '../../declarations' {
interface ServiceTypes {
'post': Post & ServiceOverloads<PostInterface> & ServiceAddons<PostInterface>;
}
}
// and this
declare module '../../declarations' {
interface ServiceTypes {
'post': Post & Service<PostInterface>;
}
}Since that Service is defined as such type Service<T> = ServiceOverloads<T> & ServiceAddons<T> & ServiceMethods<T>;
So my proposal, is to switch from using
'post': Post & ServiceAddons<PostInterface>;
to
'post': Post & Service<PostInterface>;
'post': Service<PostInterface> & Post;
update: and because of the way it's defined, the order matters (due to overloading?, or intersecting types?), if define Post & Service<PostInterface>, it will not "see" the ServiceOverloads<T> first. Which will cause this to happen.
note: the interface is different but the idea remains.
I would have to cast manually - .create(data) as PostInterface
But if the definition is switched to 'post': Post & Service<PostInterface>; It knows it is a single item, and therefore, used the correct overload method and return, without the need to cast.
The line to change is probably this
If this is alright, I can create a PR for that. Let me know what you think of it.





