Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type instantiation is excessively deep and possibly infinite.ts(2589) #22

Closed
KennethKo opened this issue May 22, 2020 · 6 comments
Closed

Comments

@KennethKo
Copy link

After the 50th or so .provideFoo( call on an injector, ts starts to complain about the deeply nested TChildContext<...>s.

microsoft/TypeScript#34933

Is there no way to bulk provide classes to the injector, or perhaps a better provide signature besides nesting child contexts?

@nicojs
Copy link
Owner

nicojs commented Aug 11, 2020

Hi @KennethKo 👋 and welcome.

How would you like the signature of "bulk provide" to work? Do you have suggestions?

@KennethKo
Copy link
Author

KennethKo commented Aug 11, 2020 via email

@nicojs
Copy link
Owner

nicojs commented Aug 12, 2020

Though imo, the token keyed class object collection would be ideal.

This is what I was thinking of as well. How about something like this?

class Foo {};
function bar() { return 'bar' };
value baz;
injector.provide({
  foo: { class: Foo },
  bar: { factory: bar, scope: Scope.Transient },
  baz: { value: baz }
});

We could allow for additional options, like scope to allow to override the default scope.

This will work in practice, however, there will be a limitation as well. For example, this will not work:

class Foo {
  static inject = tokens('bar');
  constructor(public bar: string) {} ;
};
function bar() { return 'bar' };
injector.provide({
  foo: { class: Foo },
  bar: { factory: bar },
});

In this example, Foo needs bar. This could be resolved at runtime but would be impossible to do at compile time.

What do you you think @KennethKo ?

@KennethKo
Copy link
Author

KennethKo commented Aug 12, 2020 via email

@nicojs
Copy link
Owner

nicojs commented Oct 11, 2021

I'm closing this PR as I don't think this is needed. Having multiple ways of doing things isn't part of the API. I also think the error messages TypeScript provides are getting better. Feel free to open new issues if you think of other API improvements or ways to improve the error messages.

@nsb
Copy link

nsb commented Apr 12, 2022

Love this library. Thanks a lot! But I also just hit this issue. I guess this needs to be addressed or highlighted in the docs. I don't know how to overcome this without ripping out typed-inject.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants