Skip to content

Commit

Permalink
fix: FlatDependencyTree type definition (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Vincenti <marc.vincenti@indy.fr>
  • Loading branch information
marcvincenti and marc-indy authored Oct 26, 2024
1 parent 566e390 commit b4d2d52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ type ObjectLike = Record<string, unknown>;
* All the dependencies of the declared injectables on a registry
*/
export type FlatDependencyTree<Registry extends ObjectLike> =
UnionToIntersection<
{
[key in keyof Registry]: Dependencies<Registry[key]>;
}[keyof Registry]
>;
UnionToIntersection<Dependencies<Registry[keyof Registry]>>;

/**
* All the Injectables defined by a registry
Expand Down
14 changes: 14 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ createProvider: {
// @ts-expect-error
provideMissing({});

const provideDeepMissing = createProvider({
injectables: {
foo: ({ service }: { service: number }) => service,
service: ({ nonTypedDep }) => nonTypedDep,
bar: ({ typedDep }: { typedDep: string }) => typedDep,
},
api: ['foo', 'bar'],
});
provideDeepMissing({ typedDep: 'toto', nonTypedDep: 42 });
// @ts-expect-error typedDep & nonTypedDep is missing here
provideDeepMissing();
// @ts-expect-error typedDep & nonTypedDep is missing here
provideDeepMissing({});

const provideWrongType = createProvider({
injectables: {
foo: ({ val }: { val: number }) => val,
Expand Down

0 comments on commit b4d2d52

Please sign in to comment.