Skip to content

Commit

Permalink
refactor: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Nov 23, 2024
1 parent 3ede3ee commit 6686607
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ export function createContainer({
return container;
},

register<Value>(
register<T>(
...args:
| [Constructor<Value & object>]
| [Token<Value>, Provider<Value>, RegistrationOptions?]
| [Constructor<T & object>]
| [Token<T>, Provider<T>, RegistrationOptions?]
) {
if (args.length == 1) {
const [Class] = args;
Expand Down Expand Up @@ -230,7 +230,7 @@ export function createContainer({
return container;
},

resolve<Value>(...tokens: Token<Value>[]): Value {
resolve<T>(...tokens: Token<T>[]): T {
for (const token of tokens) {
const registration = registry.get(token);
if (registration) {
Expand All @@ -244,7 +244,7 @@ export function createContainer({
throwUnregisteredError(tokens);
},

resolveAll<Value>(...tokens: Token<Value>[]): NonNullable<Value>[] {
resolveAll<T>(...tokens: Token<T>[]): NonNullable<T>[] {
for (const token of tokens) {
const registrations = registry.getAll(token);
if (registrations) {
Expand Down
4 changes: 2 additions & 2 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function Inject<Value>(token: Token<Value>): ClassFieldDecorator<Value>;
*/
export function Inject<Values extends unknown[]>(...tokens: TokenList<Values>): ClassFieldDecorator<Values[number]>;

export function Inject<Value>(...tokens: Token<Value>[]): ClassFieldDecorator<Value> {
export function Inject<T>(...tokens: Token<T>[]): ClassFieldDecorator<T> {
return (_value, _context) =>
function (this, _initialValue) {
return inject.by(this, ...tokens);
Expand All @@ -140,7 +140,7 @@ export function InjectAll<Value>(token: Token<Value>): ClassFieldDecorator<NonNu
*/
export function InjectAll<Values extends unknown[]>(...tokens: TokenList<Values>): ClassFieldDecorator<NonNullable<Values[number]>[]>;

export function InjectAll<Value>(...tokens: Token<Value>[]): ClassFieldDecorator<NonNullable<Value>[]> {
export function InjectAll<T>(...tokens: Token<T>[]): ClassFieldDecorator<NonNullable<T>[]> {
return (_value, _context) =>
function (_initialValue) {
return injectAll(...tokens);
Expand Down
10 changes: 5 additions & 5 deletions src/inject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function inject<Value>(token: Token<Value>): Value;
*/
export function inject<Values extends unknown[]>(...tokens: TokenList<Values>): Values[number];

export function inject<Value>(...tokens: Token<Value>[]): Value {
export function inject<T>(...tokens: Token<T>[]): T {
const context = ensureInjectionContext(inject);
return context.container.resolve(...tokens);
}
Expand Down Expand Up @@ -49,7 +49,7 @@ export function injectBy<Value>(thisArg: any, token: Token<Value>): Value;
*/
export function injectBy<Values extends unknown[]>(thisArg: any, ...tokens: TokenList<Values>): Values[number];

export function injectBy<Value>(thisArg: any, ...tokens: Token<Value>[]): Value {
export function injectBy<T>(thisArg: any, ...tokens: Token<T>[]): T {
const context = ensureInjectionContext(injectBy);
const resolution = context.resolution;

Expand Down Expand Up @@ -87,7 +87,7 @@ export function injectAll<Value>(token: Token<Value>): NonNullable<Value>[];
*/
export function injectAll<Values extends unknown[]>(...tokens: TokenList<Values>): NonNullable<Values[number]>[];

export function injectAll<Value>(...tokens: Token<Value>[]): NonNullable<Value>[] {
export function injectAll<T>(...tokens: Token<T>[]): NonNullable<T>[] {
const context = ensureInjectionContext(injectAll);
return context.container.resolveAll(...tokens);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ export const Injector: Type<Injector> = /*@__PURE__*/ Build(function Injector()
}

return {
inject: <Value>(...tokens: Token<Value>[]) => withCurrentContext(() => inject(...tokens)),
injectAll: <Value>(...tokens: Token<Value>[]) => withCurrentContext(() => injectAll(...tokens)),
inject: <T>(...tokens: Token<T>[]) => withCurrentContext(() => inject(...tokens)),
injectAll: <T>(...tokens: Token<T>[]) => withCurrentContext(() => injectAll(...tokens)),
};
});

0 comments on commit 6686607

Please sign in to comment.