2.0.0 Beta 2
Pre-release
Pre-release
This release fixes two issues related to types in TypeScript:
- Now, we expect that a service factory will be passed to the
factory()method. This allows us to maintain type information related to the container passed as argument to that function, so TypeScript basically can check out this code:
interface ServiceMap {
database: DatabaseInstance;
logger: LoggerInstance;
}
const container = Jimple.create<ServiceMap>();
container.set("database", container.factory( (c) => {
// now, TypeScript will know that c is an instance of the container, so you can do
c.logger.log("Connecting to the database");
return ...;
});- The type information of the function passed to the
protect()method is kept, so the function will be typed checked to what the container expects. So this works:
interface ServiceMap {
urlValidator: (url: string) => boolean
}
const container = Jimple.create<ServiceMap>();
container.set("urlValidator", container.protect( (url: string) : boolean => {
// If you change the above line to "url : number" instead of "url: string", it will throw a compile-time error
return true;
});