Open artalar opened 4 years ago
@JSMonk how would you type createObj
manually?
this does not work
const propertyName = 'propertyName'
function createObj<_a: number | string | symbol, _b>(key: _a, prop: _b): { _a: _b } {
return {
[key]: prop
}
}
const obj = createObj(propertyName, 42)
const keyValue = obj.key
const propertyNameValue = obj.propertyName
@JSMonk how would you type
createObj
manually?this does not work
const propertyName = 'propertyName' function createObj<_a: number | string | symbol, _b>(key: _a, prop: _b): { _a: _b } { return { [key]: prop } } const obj = createObj(propertyName, 42) const keyValue = obj.key const propertyNameValue = obj.propertyName
Good question. I will add computed property inside the type syntax soon.
WhAT tHe TrIn?
const foo: string = 'foo'
const bar = 'bar'
function createObj(key, prop) {
return {
[key]: prop
}
}
const objWithFoo = createObj(foo, 42)
const objWithBar = createObj(bar, 44)
const result = objWithFoo.trin + objWithBar.bar;
Currently is imposible to describe computed property name, thats is incompatible with ES
https://hegel.js.org/try#MYewdgzgLgBADgJxHApgqBPAcgQwLYowC8MA5IsmprgaQFABmArmMFAJbgzAIo5QoA8gCMAVgAoA1igwAaeEjgBKGAG86MTTF5QmCMGo1bjAbWkYAugC4FyI5oC+dJ3VCRYIMcW69+QseIUqOjY+CjyACwATEp0cW7QMOYAajgANkyEJJ6iAHTmruCJQVShBKkZWTA5uSUhNChAA