hegel icon indicating copy to clipboard operation
hegel copied to clipboard

Support computed property name

Open artalar opened this issue 5 years ago • 4 comments

Currently is imposible to describe computed property name, thats is incompatible with ES

https://hegel.js.org/try#MYewdgzgLgBADgJxHApgqBPAcgQwLYowC8MA5IsmprgaQFABmArmMFAJbgzAIo5QoA8gCMAVgAoA1igwAaeEjgBKGAG86MTTF5QmCMGo1bjAbWkYAugC4FyI5oC+dJ3VCRYIMcW69+QseIUqOjY+CjyACwATEp0cW7QMOYAajgANkyEJJ6iAHTmruCJQVShBKkZWTA5uSUhNChAA

image

artalar avatar Apr 21 '20 18:04 artalar

@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

thecotne avatar Jul 08 '20 02:07 thecotne

@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.

JSMonk avatar Jul 09 '20 21:07 JSMonk

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;

try

thecotne avatar Jul 10 '20 05:07 thecotne

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;

try

Lol, will fix it today :D

JSMonk avatar Jul 10 '20 14:07 JSMonk