Skip to content

Commit f6cf0c6

Browse files
committed
feat(context): improve typing for binding related methods
1 parent 1d658fb commit f6cf0c6

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/context/src/binding-inspector.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ export function removeNameAndKeyTags(binding: Binding<unknown>) {
136136
*
137137
* @param cls A class with optional `@bind`
138138
*/
139-
export function bindingTemplateFor(cls: Constructor<unknown>): BindingTemplate {
139+
export function bindingTemplateFor<T = unknown>(
140+
cls: Constructor<T | Provider<T>>,
141+
): BindingTemplate<T> {
140142
const spec = getBindingMetadata(cls);
141143
const templateFunctions = (spec && spec.templates) || [
142144
asClassOrProvider(cls),
@@ -198,16 +200,16 @@ export type BindingFromClassOptions = {
198200
* @param cls A class
199201
* @param options Options to customize the binding key
200202
*/
201-
export function createBindingFromClass(
202-
cls: Constructor<unknown>,
203+
export function createBindingFromClass<T = unknown>(
204+
cls: Constructor<T | Provider<T>>,
203205
options: BindingFromClassOptions = {},
204-
): Binding {
206+
): Binding<T> {
205207
const templateFn = bindingTemplateFor(cls);
206208
let key = options.key;
207209
if (!key) {
208210
key = buildBindingKey(cls, options);
209211
}
210-
const binding = Binding.bind(key).apply(templateFn);
212+
const binding = Binding.bind<T>(key).apply(templateFn);
211213
if (options.name) {
212214
binding.tag({name: options.name});
213215
}

packages/context/src/binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ export class Binding<T = BoundValue> {
473473
* easy to read.
474474
* @param key Binding key
475475
*/
476-
static bind<T = unknown>(key: BindingAddress<T>): Binding {
476+
static bind<T = unknown>(key: BindingAddress<T>): Binding<T> {
477477
return new Binding(key.toString());
478478
}
479479
}

0 commit comments

Comments
 (0)