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

[bug] can't inject values that evaluate to false #106

Open
andrei-tatar opened this issue Oct 31, 2018 · 2 comments
Open

[bug] can't inject values that evaluate to false #106

andrei-tatar opened this issue Oct 31, 2018 · 2 comments

Comments

@andrei-tatar
Copy link

andrei-tatar commented Oct 31, 2018

Hello,

If I want to register a value of 0/null/false/empty string, it won't get resolved and it will fail.

Ex:
container.register({ token: 'foo', useValue: 0 });
container.resolve('foo') fails

The problem seems to be in container.ts : registerOne(provider).

if (provider.useValue) {
  registryData.instance = provider.useValue;
}

I would suggest replacing it with

if (provider.useValue !== void 0) {
  registryData.instance = provider.useValue;
}

or

if ('useValue' in provider) {
  registryData.instance = provider.useValue;
}

to support undefined values.

Also, maybe check if a provider is valid (has only one of useClass/useValue/useFactory set on something different than undefined).

Thanks

@basedalexander
Copy link
Member

Hey! Thanks for submitting your bug report! Never thought such use case would come up. I'm gonna fix that today.

@andrei-tatar
Copy link
Author

Glad to be helpful :)

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

2 participants