Skip to content

Commit

Permalink
Upgrade to TS 4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
TiMESPLiNTER committed Jan 31, 2024
1 parent 409d153 commit fe95b9e
Show file tree
Hide file tree
Showing 12 changed files with 2,248 additions and 1,813 deletions.
7 changes: 4 additions & 3 deletions lib/cjs/container.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default interface Container {
get(service: string): any;
has(service: string): boolean;
export type ServiceKey<T> = keyof T;
export default interface Container<T> {
get<K extends ServiceKey<T>>(key: K): T[K];
has<K extends ServiceKey<T>>(key: K): boolean;
}
33 changes: 18 additions & 15 deletions lib/cjs/pimple.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Container from "./container";
import Container, { ServiceKey } from "./container";
import ServiceProvider from "./serviceProvider";
/** Declaration types */
declare type ServiceDeclaration = Function | Object;
declare type ProviderDeclaration = Function | ServiceProvider;
type ProviderDeclaration<T> = Function | ServiceProvider<T>;
type LazyServiceDefinition<T, S> = (container: Pimple<T>) => S;
type ProtectedServiceDefinition<T, S> = () => LazyServiceDefinition<T, S>;
type ServiceDefinition<T, S> = LazyServiceDefinition<T, S> | ProtectedServiceDefinition<T, S> | S;
type ServiceMap<T> = {
[key in ServiceKey<T>]: ServiceDefinition<T, T[ServiceKey<T>]>;
};
/**
* Pimple dependency injection container
*
Expand All @@ -12,7 +17,7 @@ declare type ProviderDeclaration = Function | ServiceProvider;
* @license LGPL
* @version 3.0.0
*/
export default class Pimple implements Container {
export default class Pimple<T> implements Container<T> {
/**
* @type {string}
*/
Expand All @@ -27,41 +32,39 @@ export default class Pimple implements Container {
* @private
*/
private _raw;
constructor(services?: {
[key: string]: any;
});
constructor(services?: Partial<ServiceMap<T>>);
/**
* Define a service
*/
set(name: string, service: ServiceDeclaration): Pimple;
set<K extends ServiceKey<T>>(name: K, service: ServiceDefinition<T, T[K]>): Pimple<T>;
/**
* Register a factory
*/
factory(name: string, callback: Function): Pimple;
factory<K extends ServiceKey<T>>(name: K, callback: ServiceDefinition<T, T[K]>): Pimple<T>;
/**
* Get a service instance
*/
get(name: string): any;
get<K extends ServiceKey<T>>(name: K): T[K];
/**
* Checks whether a service is registered or not
*/
has(service: string): boolean;
has<K extends ServiceKey<T>>(name: K): boolean;
/**
* Register a protected function
*/
protect(service: Function): Function;
protect<K extends ServiceKey<T>>(key: K, service: T[K]): () => T[K];
/**
* Extend a service
*/
extend(serviceName: string, service: Function): Function;
extend<K extends ServiceKey<T>>(serviceName: K, service: Function): Function;
/**
* Get a service raw definition
*/
raw(name: string): Function;
raw<K extends ServiceKey<T>>(name: K): ServiceDefinition<T, T[K]>;
/**
* Register a service provider
*/
register(provider: ProviderDeclaration): Pimple;
register(provider: ProviderDeclaration<T>): Pimple<T>;
private instanceOfServiceProvider;
}
export {};
32 changes: 17 additions & 15 deletions lib/cjs/pimple.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/cjs/pimple.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/cjs/serviceProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Pimple from "./pimple";
/**
* Service provider class for service injecting in Pimple container
*/
export default interface ServiceProvider {
register(container: Pimple): void;
export default interface ServiceProvider<T> {
register(container: Pimple<T>): void;
}
2 changes: 1 addition & 1 deletion lib/esm/container.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export declare type ServiceKey<T> = keyof T;
export type ServiceKey<T> = keyof T;
export default interface Container<T> {
get<K extends ServiceKey<T>>(key: K): T[K];
has<K extends ServiceKey<T>>(key: K): boolean;
Expand Down
10 changes: 5 additions & 5 deletions lib/esm/pimple.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Container, { ServiceKey } from "./container";
import ServiceProvider from "./serviceProvider";
/** Declaration types */
declare type ProviderDeclaration<T> = Function | ServiceProvider<T>;
declare type LazyServiceDefinition<T, S> = (container: Pimple<T>) => S;
declare type ProtectedServiceDefinition<T, S> = () => LazyServiceDefinition<T, S>;
declare type ServiceDefinition<T, S> = LazyServiceDefinition<T, S> | ProtectedServiceDefinition<T, S> | S;
declare type ServiceMap<T> = {
type ProviderDeclaration<T> = Function | ServiceProvider<T>;
type LazyServiceDefinition<T, S> = (container: Pimple<T>) => S;
type ProtectedServiceDefinition<T, S> = () => LazyServiceDefinition<T, S>;
type ServiceDefinition<T, S> = LazyServiceDefinition<T, S> | ProtectedServiceDefinition<T, S> | S;
type ServiceMap<T> = {
[key in ServiceKey<T>]: ServiceDefinition<T, T[ServiceKey<T>]>;
};
/**
Expand Down
10 changes: 5 additions & 5 deletions lib/esm/pimple.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fe95b9e

Please sign in to comment.