javascript - Disable waring 'Type of property circularly references itself in mapped type' or workaround - Stack

how i can disable this kind of error in my whole project or maybe a work around ?Type of property '

how i can disable this kind of error in my whole project or maybe a work around ?

Type of property 'UID' circularly references itself in mapped type 'Partial'.ts(2615)

So here the issue with js and vscode. If i say data type is /** @param {A} [data] */ the error are from new A({}) instance, i need fully fill the partial object or i get linter error !

if i say data type is a partial obj /** @param {Partial<A>} [data] */, now new A({}) work fine, but i get linter error to constructor !

And if i say /** @param {A|Partial<A>} [data] */ , no more error ! but all props became undefined (any) and lost types !!! Vscode IntelliSense seem little bit lost in this case. !


here a sample code, how i can say Data is a partial objet, but if nothing, default are set !!!!

test case: /** @param {A} [data]*/ - /** @param {Partial<A>} [data] */ - /** @param { A | Partial<A>} [data] */

export class A {
    /** @param {Partial<A>} [data] */ // how say is partial and also default ? 
    constructor(data) {
        /** uid global du data */
        this.UID = data.UID || 'noUID';
        this.prop = data.prop || {};
    }
    get VIEW() {
        return this.constructor.name;
    }
}

const a = new A ({UID:'g42t'})

Thanks for any help or suggest,

I would like an effective solution which allows to have a good workflow, without repetitions

i also open issue here, if is a bug ?

how i can disable this kind of error in my whole project or maybe a work around ?

Type of property 'UID' circularly references itself in mapped type 'Partial'.ts(2615)

So here the issue with js and vscode. If i say data type is /** @param {A} [data] */ the error are from new A({}) instance, i need fully fill the partial object or i get linter error !

if i say data type is a partial obj /** @param {Partial<A>} [data] */, now new A({}) work fine, but i get linter error to constructor !

And if i say /** @param {A|Partial<A>} [data] */ , no more error ! but all props became undefined (any) and lost types !!! Vscode IntelliSense seem little bit lost in this case. !


here a sample code, how i can say Data is a partial objet, but if nothing, default are set !!!!

test case: /** @param {A} [data]*/ - /** @param {Partial<A>} [data] */ - /** @param { A | Partial<A>} [data] */

export class A {
    /** @param {Partial<A>} [data] */ // how say is partial and also default ? 
    constructor(data) {
        /** uid global du data */
        this.UID = data.UID || 'noUID';
        this.prop = data.prop || {};
    }
    get VIEW() {
        return this.constructor.name;
    }
}

const a = new A ({UID:'g42t'})

Thanks for any help or suggest,

I would like an effective solution which allows to have a good workflow, without repetitions

i also open issue here, if is a bug ? https://github./microsoft/vscode/issues/108062

Share Improve this question edited Sep 19, 2022 at 16:06 Jim Buck 2,44426 silver badges42 bronze badges asked Oct 4, 2020 at 8:30 jonjon 1,8383 gold badges21 silver badges32 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

ok solved , intellisense work fine with this kind of structure. thanks all.

Little bit ugly for eye, but it fine and accesible to all parent extends constructors.

export class A {

    /**@readonly - UID ...desc */
    UID = UTILITY.create_UID();
    /**@readonly - UID2 ...desc */
    UID2 = '';
    /** @param {Partial<Omit<A, 'UID'>>} [data] */
    constructor(data,{UID2}=data) {
        this.UID2 = UID2 || 'perform default thing...';
    }
}

const a = new A ({UID2:'sada'}); // intellisence will not suggest UID here :)

Not sure why you never tagged this Typescript too. :)

But a partial of a class here doesn't really make much sense, normally types source of truth is some sort of interface / type, inferred types of course are only inferred from some sort off concrete type. Here you haven't given your class any concrete types, so Typescript will try to infer and will fail for obvious reasons, but even if it didn't it's not going to be very useful, eg. it's going to have a readonly VIEW() not something I think your after, do you really want to to be able to send an optional readonly View()??.

So the simple solution, just give data it's type your expecting.

eg.

export class A {
    /** @param {{UID?:string, prop?:object}} [data] */ 
    constructor(data) {
        /** uid global du data */
        this.UID = data.UID || 'noUID';
        this.prop = data.prop || {};
    }
    get VIEW() {
        return this.constructor.name;
    }
}

const a = new A ({UID:'g42t'})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744999976a4605434.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信