You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Current metadata keys work by simply returning an unknown value. We can improve this by adding typed keys, which would contain both the key and the value of the type, similar to branded types.
This typeKey() function can be used to create keys that can only get or set values of type T:
constnumberKey=typeKey<number>('myKey');metadata.set(numberKey,1);// ✅metadata.set(numberKey,'test');// ❌ Argument of type 'string' is not assignable to parameter of type 'number'conststoredNumber: number|null=metadata.get(numberKey);// ✅constother: string|null=metadata.get(numberKey);// ❌ Type 'number | null' is not assignable to type 'string | null'
Since maps are homogeneous, this would only be enforced at the metadata's get/set, not on the backing map.
This would also be helpful to remove #getBot() methods from metadata objects, making them completely independent from the framework, which would be useful to make other components independent as well like EventBuses.
The text was updated successfully, but these errors were encountered:
Current metadata keys work by simply returning an
unknown
value. We can improve this by adding typed keys, which would contain both the key and the value of the type, similar to branded types.It'd be something like (names may vary):
This
typeKey()
function can be used to create keys that can only get or set values of typeT
:Since maps are homogeneous, this would only be enforced at the metadata's get/set, not on the backing map.
This would also be helpful to remove
#getBot()
methods from metadata objects, making them completely independent from the framework, which would be useful to make other components independent as well likeEventBuses
.The text was updated successfully, but these errors were encountered: