Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试进行多边形填充时,typescript linter会触发错误_Javascript_Typescript_Webpack_Tslint - Fatal编程技术网

Javascript 尝试进行多边形填充时,typescript linter会触发错误

Javascript 尝试进行多边形填充时,typescript linter会触发错误,javascript,typescript,webpack,tslint,Javascript,Typescript,Webpack,Tslint,我正在尝试为我的应用程序制作一些适用于不同浏览器的多边形填充, 我有一个导入其他文件的文件,当我导入它时,typescript失败 如果我注释掉-导入“./scripts/polyfill_es5” 一切正常 如果我把它包括在内,脚本就会失败,并说- 类型“Object”上不存在属性“assignDeep” 为什么我的导入会破坏代码 这些是我的文件: Polyfill.ts: import "../scripts/polyfill_es5" interface Object { ass

我正在尝试为我的应用程序制作一些适用于不同浏览器的多边形填充, 我有一个导入其他文件的文件,当我导入它时,typescript失败

如果我注释掉
-导入“./scripts/polyfill_es5”
一切正常

如果我把它包括在内,脚本就会失败,并说-

类型“Object”上不存在属性“assignDeep”

为什么我的导入会破坏代码

这些是我的文件:

Polyfill.ts:

import "../scripts/polyfill_es5"

interface Object {
    assignDeep: (target: {}, ...sources: any[]) => object;
}

Object.prototype.assignDeep = (target: {}, ...sources: any[]) => { // .length of function is 2
    'use strict';
    if (target == null) { // TypeError if undefined or null
        throw new TypeError('Cannot convert undefined or null to object');
    }

    const to = Object(target);
    let nextSource;

    for (let index = 1; index < sources.length; index++) {
        nextSource = sources[index];

        if (nextSource != null) { // Skip over if undefined or null
            for (const nextKey in nextSource) {
                // Avoid bugs when hasOwnProperty is shadowed
                if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
                    if (typeof to[nextKey] === 'object'
                        && to[nextKey]
                        && typeof nextSource[nextKey] === 'object'
                        && nextSource[nextKey]) {
                        to[nextKey] = Object.assignDeep(Array.isArray(to[nextKey]) ? [] : {}, to[nextKey], nextSource[nextKey]);
                    } else {
                        to[nextKey] = nextSource[nextKey];
                    }
                }
            }
        }
    }
    return to;
};
interface NodeList {
    forEach : (callback : (currentValue : Node, currentIndex : number, listObj : NodeList) => void, thisArg : string|Window) => void;
}

if (typeof NodeList !== 'undefined' && !NodeList.prototype.forEach) {
    NodeList.prototype.forEach = (callback : (currentValue : Node, currentIndex : number, listObj : NodeList) => void, thisArg : string|Window) => {
        thisArg = thisArg || window;
        for (let i = 0; i < this.length; i++) {
            callback.call(thisArg, this[i], i, this);
        }
    };
}
导入“./脚本/polyfill_es5” 接口对象{ assignDeep:(目标:{},…源:any[])=>对象; } Object.prototype.assignDeep=(目标:{},…源代码:any[])=>{//。函数长度为2 "严格使用",; 如果(target==null){//TypeError如果未定义或为null 抛出新的TypeError('无法将未定义或null转换为对象'); } 常数to=对象(目标); 让nextSource; for(让index=1;index polyfill_es5.ts:

import "../scripts/polyfill_es5"

interface Object {
    assignDeep: (target: {}, ...sources: any[]) => object;
}

Object.prototype.assignDeep = (target: {}, ...sources: any[]) => { // .length of function is 2
    'use strict';
    if (target == null) { // TypeError if undefined or null
        throw new TypeError('Cannot convert undefined or null to object');
    }

    const to = Object(target);
    let nextSource;

    for (let index = 1; index < sources.length; index++) {
        nextSource = sources[index];

        if (nextSource != null) { // Skip over if undefined or null
            for (const nextKey in nextSource) {
                // Avoid bugs when hasOwnProperty is shadowed
                if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
                    if (typeof to[nextKey] === 'object'
                        && to[nextKey]
                        && typeof nextSource[nextKey] === 'object'
                        && nextSource[nextKey]) {
                        to[nextKey] = Object.assignDeep(Array.isArray(to[nextKey]) ? [] : {}, to[nextKey], nextSource[nextKey]);
                    } else {
                        to[nextKey] = nextSource[nextKey];
                    }
                }
            }
        }
    }
    return to;
};
interface NodeList {
    forEach : (callback : (currentValue : Node, currentIndex : number, listObj : NodeList) => void, thisArg : string|Window) => void;
}

if (typeof NodeList !== 'undefined' && !NodeList.prototype.forEach) {
    NodeList.prototype.forEach = (callback : (currentValue : Node, currentIndex : number, listObj : NodeList) => void, thisArg : string|Window) => {
        thisArg = thisArg || window;
        for (let i = 0; i < this.length; i++) {
            callback.call(thisArg, this[i], i, this);
        }
    };
}
接口节点列表{
forEach:(callback:(currentValue:Node,currentIndex:number,listObj:NodeList)=>void,thisArg:string | Window)=>void;
}
if(节点列表的类型!='undefined'&&!节点列表.prototype.forEach){
NodeList.prototype.forEach=(回调:(currentValue:Node,currentIndex:number,listObj:NodeList)=>void,thisArg:string | Window)=>{
thisArg=thisArg | |窗口;
for(设i=0;i
您需要进行全局扩充:

declare global {
  interface Object {
    assignDeep: (target: {}, ...sources: any[]) => object;
  }
}

当文件包含顶级导入/导出语句时,TypeScript编译器将该文件视为模块文件。因此,您的
接口对象{}
是文件的本地对象,而不是全局
对象

您需要执行全局扩充:

declare global {
  interface Object {
    assignDeep: (target: {}, ...sources: any[]) => object;
  }
}

当文件包含顶级导入/导出语句时,TypeScript编译器将该文件视为模块文件。因此,您的
接口对象{}
是文件的本地对象,而不是全局
对象

非常感谢您的帮助谢谢您的帮助