Checklist
[x] Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
[x] Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/
Is your feature request related to a problem? Please describe.
I wrote code like:
const el = doc.getXmlElement('key')
const attrs = el.getAttributes()
I incorrectly assumed that attrs have to be strings because doc.getXmlElement casts to YXmlElement<{[key:string]:string}> here:
|
getXmlElement (name = '') { |
|
return /** @type {YXmlElement<{[key:string]:string}>} */ (this.get(name, YXmlElement)) |
|
} |
but in fact XMLElement can have attributes of any type:
|
* @template {{ [key: string]: any }} [Attrs={ [key: string]: string }] |
|
* @template {any} [Children=any] |
|
* @extends YXmlFragment<Children,Attrs> |
|
*/ |
|
export class YXmlElement extends YXmlFragment { |
|
constructor (nodeName = 'UNDEFINED') { |
|
super() |
|
this.nodeName = nodeName |
|
/** |
|
* @type {Map<string, any>|null} |
|
*/ |
|
this._prelimAttrs = new Map() |
|
} |
or of type ValueTypes in v13:
|
* * An YXmlElement has attributes (key value pairs) |
|
* * An YXmlElement has childElements that must inherit from YXmlElement |
|
* |
|
* @template {{ [key: string]: ValueTypes }} [KV={ [key: string]: string }] |
|
*/ |
|
export class YXmlElement extends YXmlFragment { |
I then tried to correct it by writing
const el = doc.getXmlElement<[key:string]: any}>('key')
But typechecker rejected it because getXmlElement does not accept type arguments
Describe the solution you'd like
- Make the default return type annotation use
any to protect users
- Add both type arguments to
doc.getXmlElement
Describe alternatives you've considered
None
Additional context
Add any other context or screenshots about the feature request here.
Checklist
[x] Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
[x] Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/
Is your feature request related to a problem? Please describe.
I wrote code like:
I incorrectly assumed that attrs have to be strings because
doc.getXmlElementcasts toYXmlElement<{[key:string]:string}>here:yjs/src/utils/Doc.js
Lines 302 to 304 in 19b5134
but in fact
XMLElementcan have attributes ofanytype:yjs/src/types/YXmlElement.js
Lines 27 to 39 in 19b5134
or of type
ValueTypesin v13:yjs/src/types/YXmlElement.js
Lines 25 to 30 in 4120d72
I then tried to correct it by writing
But typechecker rejected it because
getXmlElementdoes not accept type argumentsDescribe the solution you'd like
anyto protect usersdoc.getXmlElementDescribe alternatives you've considered
None
Additional context
Add any other context or screenshots about the feature request here.