diff --git a/src/types/YXmlElement.js b/src/types/YXmlElement.js index 7b18be69..1c1f3190 100644 --- a/src/types/YXmlElement.js +++ b/src/types/YXmlElement.js @@ -20,7 +20,7 @@ import { /** * An YXmlElement imitates the behavior of a - * {@link https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element}. + * https://developer.mozilla.org/en-US/docs/Web/API/Element|Dom Element * * * An YXmlElement has attributes (key value pairs) * * An YXmlElement has childElements that must inherit from YXmlElement diff --git a/src/utils/Doc.js b/src/utils/Doc.js index e809e7ec..0d8d471b 100644 --- a/src/utils/Doc.js +++ b/src/utils/Doc.js @@ -181,6 +181,7 @@ export class Doc extends Observable { * Define all types right after the Yjs instance is created and store them in a separate object. * Also use the typed methods `getText(name)`, `getArray(name)`, .. * + * @template {typeof AbstractType} Type * @example * const y = new Y(..) * const appState = { @@ -189,12 +190,12 @@ export class Doc extends Observable { * } * * @param {string} name - * @param {Function} TypeConstructor The constructor of the type definition. E.g. Y.Text, Y.Array, Y.Map, ... - * @return {AbstractType} The created type. Constructed with TypeConstructor + * @param {Type} TypeConstructor The constructor of the type definition. E.g. Y.Text, Y.Array, Y.Map, ... + * @return {InstanceType} The created type. Constructed with TypeConstructor * * @public */ - get (name, TypeConstructor = AbstractType) { + get (name, TypeConstructor = /** @type {any} */ (AbstractType)) { const type = map.setIfUndefined(this.share, name, () => { // @ts-ignore const t = new TypeConstructor() @@ -220,12 +221,12 @@ export class Doc extends Observable { t._length = type._length this.share.set(name, t) t._integrate(this, null) - return t + return /** @type {InstanceType} */ (t) } else { throw new Error(`Type with the name ${name} has already been defined with a different constructor`) } } - return type + return /** @type {InstanceType} */ (type) } /** @@ -236,8 +237,7 @@ export class Doc extends Observable { * @public */ getArray (name = '') { - // @ts-ignore - return this.get(name, YArray) + return /** @type {YArray} */ (this.get(name, YArray)) } /** @@ -247,7 +247,6 @@ export class Doc extends Observable { * @public */ getText (name = '') { - // @ts-ignore return this.get(name, YText) } @@ -259,8 +258,7 @@ export class Doc extends Observable { * @public */ getMap (name = '') { - // @ts-ignore - return this.get(name, YMap) + return /** @type {YMap} */ (this.get(name, YMap)) } /** @@ -270,8 +268,7 @@ export class Doc extends Observable { * @public */ getXmlElement (name = '') { - // @ts-ignore - return this.get(name, YXmlElement) + return /** @type {YXmlElement<{[key:string]:string}>} */ (this.get(name, YXmlElement)) } /** @@ -281,7 +278,6 @@ export class Doc extends Observable { * @public */ getXmlFragment (name = '') { - // @ts-ignore return this.get(name, YXmlFragment) } diff --git a/tests/y-xml.tests.js b/tests/y-xml.tests.js index 22f12be9..a9395c2d 100644 --- a/tests/y-xml.tests.js +++ b/tests/y-xml.tests.js @@ -189,7 +189,6 @@ export const testClone = _tc => { const third = new Y.XmlElement('p') yxml.push([first, second, third]) t.compareArrays(yxml.toArray(), [first, second, third]) - const cloneYxml = yxml.clone() ydoc.getArray('copyarr').insert(0, [cloneYxml]) t.assert(cloneYxml.length === 3) @@ -217,7 +216,6 @@ export const testFormattingBug = _tc => { export const testElement = _tc => { const ydoc = new Y.Doc() const yxmlel = ydoc.getXmlElement() - const text1 = new Y.XmlText('text1') const text2 = new Y.XmlText('text2') yxmlel.insert(0, [text1, text2])