Skip to content

Commit

Permalink
feat: Allow isInjectable and isInjectionToken to be used for type nar…
Browse files Browse the repository at this point in the history
…rowing

Signed-off-by: Sebastian Malton <[email protected]>
  • Loading branch information
Nokel81 authored and Iku-turso committed May 2, 2023
1 parent 1508ea8 commit b82c1c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/injectable/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ export const instantiationDecoratorToken: InjectionToken<

export const registrationCallbackToken: RegistrationCallback;
export const deregistrationCallbackToken: RegistrationCallback;
export const isInjectable: (thing: any) => boolean;
export const isInjectionToken: (thing: any) => boolean;
export const isInjectable: (thing: unknown) => thing is Injectable<unknown, unknown, unknown>;
export const isInjectionToken: (thing: unknown) => thing is InjectionToken<unknown, unknown>;

export function createContainer(
containerId: string,
Expand Down
12 changes: 12 additions & 0 deletions packages/injectable/core/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
createInjectionTargetDecorator,
SpecificInject,
InjectionToken,
isInjectable,
isInjectionToken,
} from '.';

const di = createContainer('some-container');
Expand Down Expand Up @@ -45,6 +47,16 @@ const decoratorForToken = getInjectable({
injectionToken: instantiationDecoratorToken,
});

const foo: unknown = "number";

if (isInjectable(foo)) {
expectType<Injectable<unknown, unknown, unknown>>(foo);
}

if (isInjectionToken(foo)) {
expectType<InjectionToken<unknown, unknown>>(foo);
}

// given injectable without instantiation paramater and decorator targeting the injectable, typing is ok
const someInjectableToBeDecorated = getInjectable({
id: 'some-injectable-to-be-decorated',
Expand Down

0 comments on commit b82c1c9

Please sign in to comment.