The idea behind this PR is that it's often useful when working in Typescript to be able to say that your service names will come from some pre-defined list, to (e.g.) prevent typos when declaring dependencies, or to get the compiler to error if you remove a service that another service still depends on. This PR makes that possible.
Usage:
type LegalName = 'Service1' | 'Service2';
const bottle = new Bottle<LegalName>();
bottle.constant('Service1', 3); // Ok
bottle.constant('Service3', 3); // Errors, no Service3
bottle.service('Service1', class {}, 'Service2');
bottle.service('Service2', class {}, 'Service3'); // errors, no Service3.
Note that the type parameter for Bottle (LegalName in the example) will default to string if not provided, so this won't break any existing uses or require extra boilerplate for users who don't care about this safety.
The idea behind this PR is that it's often useful when working in Typescript to be able to say that your service names will come from some pre-defined list, to (e.g.) prevent typos when declaring dependencies, or to get the compiler to error if you remove a service that another service still depends on. This PR makes that possible.
Usage:
Note that the type parameter for
Bottle
(LegalName
in the example) will default tostring
if not provided, so this won't break any existing uses or require extra boilerplate for users who don't care about this safety.