Let's say I have a function:
angular.forEach(myElements, function prepareElements(myEl: HTMLElement, index) {
myEl.dataset.myProperty = "whatever";
})
The problem I get is
error TS2094: The property 'myProperty' does not exist on value of type 'DOMStringMap'
I don't really understand the interface
in lib.d.ts
interface DOMStringMap {
}
declare var DOMStringMap: {
prototype: DOMStringMap;
new (): DOMStringMap;
}
then later on...
interface HTMLElement {
dataset: DOMStringMap;
hidden: boolean;
msGetInputContext(): MSInputMethodContext;
}
Is it just me or is this a little unclear?
I tried casting it <DOMStringMap>myEl.dataset.myProperty = "whatever"
, which did nothing...
The DOMStringMap interface is empty because the spec is not finalized : https://developer.mozilla.org/en/docs/Web/API/DOMStringMap
In the meantime you can simply use: myEl.dataset['myProperty'] = "whatever";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With