You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there any plan to allow implicit types when a class is anyways implementing an interface, function types are well defined, but still need to redeclare function types on the class:
thanks in advance
β Viability Checklist
This wouldn't be a breaking change in existing TypeScript/JavaScript code
This wouldn't change the runtime behavior of existing JavaScript code
This could be implemented without emitting different JS based on the types of the expressions
This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
class UserServiceImpl implements UserService {
// We have to repeat types even though they're defined in the interface
async getUser(id: string): Promise { ... }
async updateUser(user: User): Promise { ... }
}
Since the class explicitly implements the interface, TypeScript could infer these types without us having to redeclare them:
class UserServiceImpl implements UserService {
// Types could be inferred from the interface
async getUser(id) { ... }
async updateUser(user) { ... }
}
This would:
Follow the DRY principle
Reduce boilerplate
Lower maintenance burden when types change
Decrease chances of inconsistencies
Support TypeScript's goal of type safety with minimal overhead
Is there any plan to implement this feature? It seems like a natural evolution of TypeScript's powerful type inference capabilities.
π» Use Cases
What do you want to use this for? Write cleaner code
What shortcomings exist with current approaches? It would not be a breaking change
What workarounds are you using in the meantime? No workarounds, still writing again the parameters types for functions
The text was updated successfully, but these errors were encountered:
π Search Terms
Hi all,
is there any plan to allow implicit types when a class is anyways implementing an interface, function types are well defined, but still need to redeclare function types on the class:
thanks in advance
β Viability Checklist
β Suggestion
It would be cleaner if developer is not forced to redeclare function types when implementing functions coming from an interface
π Motivating Example
I'd like to propose an enhancement that could significantly reduce code duplication and improve developer experience.
Currently, when a class implements an interface, we're required to redeclare method types even though they're already defined in the interface:
interface UserService {
getUser(id: string): Promise;
updateUser(user: User): Promise;
}
class UserServiceImpl implements UserService {
// We have to repeat types even though they're defined in the interface
async getUser(id: string): Promise { ... }
async updateUser(user: User): Promise { ... }
}
Since the class explicitly implements the interface, TypeScript could infer these types without us having to redeclare them:
class UserServiceImpl implements UserService {
// Types could be inferred from the interface
async getUser(id) { ... }
async updateUser(user) { ... }
}
This would:
Is there any plan to implement this feature? It seems like a natural evolution of TypeScript's powerful type inference capabilities.
π» Use Cases
The text was updated successfully, but these errors were encountered: