Property 'assign' does not exist on type 'ObjectConstructor'

后端 未结 8 1652
醉话见心
醉话见心 2020-12-02 14:47

I am using TypeScript in my application, where I use function:

Object.assign(this.success, success.json())

However, during compilation, I r

8条回答
  •  暖寄归人
    2020-12-02 15:36

    I faced this issue when testing a React application with Jest using @testing-library/react. The fix for me was to add the following to my setupTests.ts:

    declare global {
        interface Object {
            /**
             * Returns an array of values of the enumerable properties of an object
             * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
             */
            values(o: { [s: string]: T } | ArrayLike): T[];
    
            /**
             * Returns an array of values of the enumerable properties of an object
             * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
             */
            values(o: {}): any[];
    
            /**
             * Returns an array of key/values of the enumerable properties of an object
             * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
             */
            entries(o: { [s: string]: T } | ArrayLike): [string, T][];
    
            /**
             * Returns an array of key/values of the enumerable properties of an object
             * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
             */
            entries(o: {}): [string, any][];
        }
    }
    

提交回复
热议问题