From d9e6e605c55d7444cc599a6b2129a9885678b0ee Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Fri, 3 Apr 2020 19:25:06 -0700 Subject: [PATCH] [BUGFIX] Fixes the types of manager return values Currently `setManager` APIs return object as a type, when they _should_ return the value they were passed. This updates the types to make that happen using generics. --- packages/@glimmer/core/src/managers/index.ts | 33 +++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/@glimmer/core/src/managers/index.ts b/packages/@glimmer/core/src/managers/index.ts index b2f859664..c09ae7fc1 100644 --- a/packages/@glimmer/core/src/managers/index.ts +++ b/packages/@glimmer/core/src/managers/index.ts @@ -46,10 +46,10 @@ const MANAGER_INSTANCES: WeakMap< const getPrototypeOf = Object.getPrototypeOf; -export function setManager( +export function setManager( wrapper: ManagerWrapper, - obj: {} -): {} { + obj: Def +): Def { MANAGERS.set(obj, wrapper); return obj; } @@ -95,10 +95,11 @@ function getManagerInstanceForOwner( /////////// -export function setModifierManager( - factory: ManagerFactory>, - definition: ModifierDefinition -): {} { +export function setModifierManager< + StateBucket, + Def extends ModifierDefinition, + Owner extends object = object +>(factory: ManagerFactory>, definition: Def): Def { return setManager({ factory, type: 'modifier' }, definition); } @@ -113,10 +114,11 @@ export function getModifierManager( } } -export function setHelperManager( - factory: ManagerFactory>, - definition: HelperDefinition -): {} { +export function setHelperManager< + StateBucket, + Def extends HelperDefinition, + Owner extends object = object +>(factory: ManagerFactory>, definition: Def): Def { return setManager({ factory, type: 'helper' }, definition); } @@ -131,10 +133,11 @@ export function getHelperManager( } } -export function setComponentManager( - factory: ManagerFactory>, - definition: ComponentDefinition -): {} { +export function setComponentManager< + StateBucket, + Def extends ComponentDefinition, + Owner extends object = object +>(factory: ManagerFactory>, definition: Def): Def { return setManager({ factory, type: 'component' }, definition); }