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

feat(core): add optional token #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Fyzu
Copy link

@Fyzu Fyzu commented May 9, 2022

Sometimes some dependencies are optional, but now there is no way to specify such dependencies correctly.

My suggestion is to add an optional token:

const foo = tokenOptional('foo')<'foo'>()

const bar = injectable(foo, (foo: 'foo' | undefined) =>
  foo !== undefined ? `${foo}bar` : 'baz'
)

bar({}) // ✅ valid

@Fyzu
Copy link
Author

Fyzu commented May 9, 2022

@raveclassic what do u think?

@raveclassic
Copy link
Owner

raveclassic commented May 12, 2022

@Fyzu Hm, such case should be already supported by the regular token function: const foo = token('foo')<'foo' | undefined>(), we just need to correctly produce UnknownDependencyTree with optional: true.

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

Successfully merging this pull request may close these issues.

2 participants