UNPKG

@loopback/docs

Version:
51 lines (32 loc) 1.52 kB
--- lang: en title: 'API docs: context.context.getsync_1' keywords: LoopBack 4.0, LoopBack 4 sidebar: lb4_sidebar permalink: /doc/en/lb4/apidocs.context.context.getsync_1.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [Context](./context.context.md) &gt; [getSync](./context.context.getsync_1.md) ## Context.getSync() method Get the synchronous value bound to the given key, optionally return a (deep) property of the bound value. This method throws an error if the bound value requires async computation (returns a promise). You should never rely on sync bindings in production code. <b>Signature:</b> ```typescript getSync<ValueType>(keyWithPath: BindingAddress<ValueType>, options?: ResolutionOptions): ValueType | undefined; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | keyWithPath | <code>BindingAddress&lt;ValueType&gt;</code> | The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve. | | options | <code>ResolutionOptions</code> | Options for resolution. | <b>Returns:</b> `ValueType | undefined` The bound value, or undefined when an optional binding is not found. ## Example ```ts // get "rest" property from the value bound to "config" // use "undefined" when no config is provided const config = await ctx.getSync<RestComponentConfig>('config#rest', { optional: true }); ```