I'm facing a challenge in figuring out how to achieve a specific task. We have a function called createActions
that requires an object type and a string as a key.
function createActions<T, Tkey extends string>(key: Tkey) {
return function(obj: T) {
return {[key]: obj}
}
}
My goal is to automatically infer the type of Tkey
, while ensuring strong typing for T
. The objective here is to enable developers to access defined properties in a properly typed manner. For instance, if the specified key is a
, calling createActions('a')({}).b
should trigger a compiler error since b
is not part of type {a: {}}
.
This concept is an extension of our existing implementation, which can be viewed at: https://github.com/CaliStyle/ngrx-poly/blob/master/src/app/ngrx-poly/actions/depth-one-action-map.ts. Any insights on how to tackle this challenge?