Augment Key during Type Mapping · Issue #12754 · microsoft/TypeScript (original) (raw)

Aurelia follows the convention that for any field foo, when foo is changed by the framework, then an attempt to call fooChanged() is made. There is (seemingly) no way to describe this convention as a type (automatically) via the Mapped Type functionality alone.

I would like to open discussion to the prospect of augmenting property keys during mapping.

For example: via arthimetic:

type Changed = {
[ P in keyof T ] + "Changed" ?: Function; }

class Foo{ field:number; }

let foo = <Foo & Changed> new Foo();

foo.field = 10;

if(foo.fieldChanged) foo.fieldChanged();

in this use-case specifically it probably would require #12424 too, but that is beside the point here.