php-fig / container

MIT License
9.95k stars 53 forks source link

Add generics to ContainerInterface #44

Open nicolas-grekas opened 2 years ago

nicolas-grekas commented 2 years ago

WDYT?

mnapoli commented 2 years ago

Duplicates #35?

nicolas-grekas commented 2 years ago

Quite close indeed. I'd just not add generics to the keys. Despite #35 being closed, I still think this would be a good idea. Locators scoped to some interface are quite common. It'd be great to hint autocompletion about them: ContainerInterface<Foo> $container->get('bar')->... and be suggested with what Foo provides.

The fact that psalm/phpstan would complain about this shouldn't be a blocker to me. Eg they could stop complaining when the template type is of mixed.

ro0NL commented 2 years ago

to clarify, TS is super explicit here :) T extends String vs T extends String = String vs T = String vs T