Skip to content

Commit

Permalink
feat(context): improve typing for binding related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Mar 15, 2019
1 parent 1d658fb commit f6cf0c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/context/src/binding-inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export function removeNameAndKeyTags(binding: Binding<unknown>) {
*
* @param cls A class with optional `@bind`
*/
export function bindingTemplateFor(cls: Constructor<unknown>): BindingTemplate {
export function bindingTemplateFor<T = unknown>(
cls: Constructor<T | Provider<T>>,
): BindingTemplate<T> {
const spec = getBindingMetadata(cls);
const templateFunctions = (spec && spec.templates) || [
asClassOrProvider(cls),
Expand Down Expand Up @@ -198,16 +200,16 @@ export type BindingFromClassOptions = {
* @param cls A class
* @param options Options to customize the binding key
*/
export function createBindingFromClass(
cls: Constructor<unknown>,
export function createBindingFromClass<T = unknown>(
cls: Constructor<T | Provider<T>>,
options: BindingFromClassOptions = {},
): Binding {
): Binding<T> {
const templateFn = bindingTemplateFor(cls);
let key = options.key;
if (!key) {
key = buildBindingKey(cls, options);
}
const binding = Binding.bind(key).apply(templateFn);
const binding = Binding.bind<T>(key).apply(templateFn);
if (options.name) {
binding.tag({name: options.name});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/context/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ export class Binding<T = BoundValue> {
* easy to read.
* @param key Binding key
*/
static bind<T = unknown>(key: BindingAddress<T>): Binding {
static bind<T = unknown>(key: BindingAddress<T>): Binding<T> {
return new Binding(key.toString());
}
}

0 comments on commit f6cf0c6

Please sign in to comment.