container icon indicating copy to clipboard operation
container copied to clipboard

Add generics to ContainerInterface

Open nicolas-grekas opened this issue 3 years ago • 2 comments

WDYT?

nicolas-grekas avatar May 05 '22 16:05 nicolas-grekas

Duplicates #35?

mnapoli avatar May 05 '22 16:05 mnapoli

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.

nicolas-grekas avatar May 05 '22 17:05 nicolas-grekas

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

ro0NL avatar May 06 '22 19:05 ro0NL