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

createInjectionToken wrongfully disregards falsy argument passed to generated provider function #161

Closed
diegovilar opened this issue Nov 19, 2023 · 0 comments · Fixed by #162

Comments

@diegovilar
Copy link
Contributor

Suppose for whatever reason you want to provide a value like this:

const [injectSomeValue, provideSomeValue] = createInjectionToken(factory);

function factory(): number {
  return 1;
}

Later on you actually provide a value so it can be injected instead of the factory generated one:

providers: [provideSomeValue(0)]

Because of how the provider function (provideSomeValue) created by createProvideFn decides whether to use the configured factory or the value that was provided to provideSomeValue, any provided value that evaluates to falsy (0, "", false, null, undefined, etc) will be disregarded and the factory will be used instead.

Instead of evaluating the optionally passed argument itself, maybe evaluate if an argument was actually passed instead?

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