这就是我在我的index.js中所做的,以避免向我的所有用户提供多填充。
index.js
const renderApp = () => {
ReactDOM.render(
<App
firebase={firebase}
/>
,document.getElementById("root") as HTMLElement
);
};
/* ############################ */
/* #### CHECK FOR POLYFILL #### */
/* ############################ */
if (
'fetch' in window &&
'Intl' in window &&
'URL' in window &&
'Map' in window &&
'forEach' in NodeList.prototype &&
'startsWith' in String.prototype &&
'endsWith' in String.prototype &&
'includes' in String.prototype &&
'includes' in Array.prototype &&
'assign' in Object &&
'entries' in Object &&
'keys' in Object
) {
renderApp();
} else {
import(
/* webpackChunkName: "core-js-stable" */
/* webpackMode: "lazy" */
'core-js/stable' // <---- DYNAMIC IMPORTED "core-js/stable"
).then(renderApp);
}但是,我在core-js/stable包的动态导入中得到了“隐式任何类型”警告。而且,由于我的工作通常没有--noImplicitAny标志,所以我的项目不会那样编译。

奇怪的是我安装了@types/core-js package

为什么类型记录找不到核心-js包的类型?
注意:--如果我用常规的import "core-js/stable"导入它,就不会收到这个警告/错误。
另外,如果我只动态导入core-js而没有/stable路径,则不会收到任何警告/错误。
就像,这很好:
import(
/* webpackChunkName: "core-js-stable" */
/* webpackMode: "lazy" */
'core-js'
).then(renderApp);tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"esModuleInterop": true,
"jsx": "react",
"module": "CommonJS",
"sourceMap": true,
"strictNullChecks": true,
"target": "ES5",
"paths": {
"@src/*": ["./src/*"],
}
},
"include": [
"src/**/*"
]
}发布于 2020-08-03 13:52:21
以下是我为消除错误/警告所做的工作。
这个想法是从打字文档中得到的:
https://www.typescriptlang.org/docs/handbook/namespaces.html#working-with-other-javascript-libraries
我为环境声明、和一个index.d.ts文件创建了这个文件夹
/types/ambient/index.d.ts
index.d.ts
declare module 'core-js/stable';在index.tsx上,您必须使用三重斜杠指令引用您创建的d.ts文件。
index.tsx
/// <reference path="./types/ambient/index.d.ts"/>
(...) OTHER CODE
import(
/* webpackChunkName: "core-js-stable" */
/* webpackMode: "lazy" */
'core-js/stable'
).then(renderApp);现在一切正常运行,没有错误/警告。

https://stackoverflow.com/questions/63228296
复制相似问题