Is there a way to disable this specific error throughout my entire project, or is there a workaround available?
The error message states: "Type of property 'UID' circularly references itself in mapped type 'Partial'.ts(2615)"
https://i.sstatic.net/tzIYH.png
The issue seems to be with JavaScript and Visual Studio Code. When I define the data type as /** @param {A} [data] */
, I encounter errors when creating a new instance with new A({})
where I need to fully fill the partial object to avoid a linter error!
https://i.sstatic.net/bL7Q2.png
If I specify the data type as a partial object
/** @param {Partial<A>} [data] */
, then the new A({})
works fine, but I receive linter errors related to the constructor!
https://i.sstatic.net/jtuQ2.png
Alternatively, if I use
/** @param {A|Partial<A>} [data] */
, the errors disappear but all properties become undefined (any) and lose their types!!! Visual Studio Code IntelliSense appears to be confused in this scenario!
https://i.sstatic.net/uSeu3.png
Here's a sample code snippet. How can I specify that Data is a partial object, but with default values if nothing is provided?
Test case: /** @param {A} [data]*/
-
/** @param {Partial<A>} [data] */
- /** @param { A | Partial<A>} [data] */
export class A {
/** @param {Partial<A>} [data] */ // How can I indicate that it's partial but also has default values?
constructor(data) {
/** uid global of the data */
this.UID = data.UID || 'noUID';
this.prop = data.prop || {};
}
get VIEW() {
return this.constructor.name;
}
}
const a = new A ({UID:'g42t'})
Any help or suggestions would be greatly appreciated.
I'm looking for an efficient solution that improves workflow and minimizes repetition.
I have also opened an issue here. Is it possibly a bug? https://github.com/microsoft/vscode/issues/108062