Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class implementing interface implicit types #61425

Closed
6 tasks done
asotog opened this issue Mar 14, 2025 Β· 2 comments
Closed
6 tasks done

Class implementing interface implicit types #61425

asotog opened this issue Mar 14, 2025 Β· 2 comments
Labels
Duplicate An existing issue was already created

Comments

@asotog
Copy link

asotog commented Mar 14, 2025

πŸ” 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:

Image

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:

  • 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

  1. What do you want to use this for? Write cleaner code
  2. What shortcomings exist with current approaches? It would not be a breaking change
  3. What workarounds are you using in the meantime? No workarounds, still writing again the parameters types for functions
@whzx5byb
Copy link

Duplicate of #32082.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 17, 2025
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants