请问老师关于tsc编译Promise
来源:12-5 驯服tsc - tsconfig 编写第一部分

hy_wang
2021-10-26
请问下老师我的项目里代码全部使用tsc编译。我想让ts让babel一样可以编译我的Promise拥有Promise的polyfill。查阅官网我发现配置lib库就可以解决。但是我这么配置后发现还是无效。
{
"exclude": [
"node_modules",
"**/*.stories.tsx",
"**/*.test.tsx"
],
"include": [
"./lib/"
],
"compilerOptions": {
"target": "es5",
"lib": ["dom", "ESNext", "es5", "es2015.promise"],
"jsx": "react",
"module": "ESNext",
"moduleResolution": "node",
"baseUrl": "./",
"paths": {},
"allowJs": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"alwaysStrict": true,
"declaration": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"allowSyntheticDefaultImports": true,
"outDir": "./types"
}
}
请问老师我应该如何处理呢
写回答
1回答
-
张轩
2021-10-28
同学你好 lib 和编译出来的代码没有关系。请看问答:https://github.com/microsoft/TypeScript/issues/14308
The
lib
option is only for typechecking, it doesn't affect codegen.针对低版本的浏览器不支持 Promise 的话,需要手动的设置 polyfill
这文章写的很好,强烈建议看一下:https://juejin.cn/post/6844903869579788296 正好解决你的问题
032021-10-29
相似问题