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

inject optional parameters #207

Open
Harshita-mindfire opened this issue Aug 22, 2022 · 0 comments
Open

inject optional parameters #207

Harshita-mindfire opened this issue Aug 22, 2022 · 0 comments
Assignees

Comments

@Harshita-mindfire
Copy link

Extremely new to the DI tsyringe, how do we handle optional parameters with@inject decorator?
With the below setup, I get the following error:

Cannot inject the dependency siteUtils in UtilsWeb, Reason: TypeInfo not known for "undefined"

My use case is : the siteUrl and enablePrettyLinks can have undefined values. They are being read from a .yml file

-------------
  container.register("siteUrl", { useValue: siteUrl }); // siteUrl can have undefined value
  container.register("enablePrettyLinks", { useValue: enablePrettyLinks }); // enablePrettyLinks can have undefined value
------------------

@injectable()
export class UtilsWeb {
  constructor(
    @inject("siteUrl") private siteUrl?: string,
    @inject("enablePrettyLinks") private enablePrettyLinks?: boolean
  ) {}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants