![](/img/trans.png)
[英]Why is export from index.tsx file undefined? (React + Typescript)
[英]export JSON file from index file in typescript
在我的 typescript 項目中,我能夠在文件夾的 index.ts 中重新導出我的默認導出。
例如:
export { default as BaseError } from "./errorResponse";
但我無法像這樣導出 JSON 文件。
export * as configFiles from "./config";
如何捆綁和導出 JSON 文件,以便我可以在 tsconfig 的路徑中使用它
{
"compilerOptions": {
"paths": {
"@errorClass": ["src/helpers/errorClasses"],
"@config": ["src/config"],
"@routes": ["src/routes"]
},
}
在tsconfig.json
文件中添加以下選項:
{
"compilerOptions": {
"esModuleInterop": true,
"resolveJsonModule": true
}
}
更新tsconfig
文件后導出 configFile,如下所示:
export { default as configFiles } from "./config.json";
現在要在您的代碼中configFiles
配置文件,請使用以下代碼:
import { configFiles } from "./file-path-to-configFiles-variable";
console.log(configFiles);
示例tsconfig.json
"compilerOptions": {
"baseUrl": "src",
...
"paths": {
"@config":["src/config/*"],
...
},`
import { xConfig } from '@config/index';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.