打字稿构建创建不正确的导入路径
Typescript build creates incorrect import path
当我 运行 tsc.exe 我最终得到指向源文件夹的导入路径。
dist/typescript-angular中的文件由swagger-codegen使用目标语言typescript-angular.
生成
tsc -d --types node --target es5 --moduleResolution node --sourceMap true --experimentalDecorators --rootDir dist/typescript-angular/fes_wecare_appointment/model/ --outDir dist/node-models/fes_wecare_appointment/ dist/typescript-angular/fes_wecare_appointment/model/*.ts
我最终从源文件夹导入
export declare namespace WecareNewAppointment {
type AppointmentTypeEnum = 'video' | 'audio' | 'chat';
const AppointmentTypeEnum: {
Video: import("../../../../../../../../../Users/x/projects/x/y/dist/typescript-angular/fes_wecare_appointment/model/slot").Slot.SlotTypeEnum;
Audio: import("../../../../../../../../../Users/x/projects/x/y/dist/typescript-angular/fes_wecare_appointment/model/slot").Slot.SlotTypeEnum;
Chat: import("../../../../../../../../../Users/x/projects/x/y/dist/typescript-angular/fes_wecare_appointment/model/slot").Slot.SlotTypeEnum;
};
}
无需过多参考源文件夹中的插槽类型。它应该是这样的。
export declare namespace WecareNewAppointment {
type AppointmentTypeEnum = 'video' | 'audio' | 'chat';
const AppointmentTypeEnum: {
Video: import("./slot").Slot.SlotTypeEnum;
Audio: import("./slot").Slot.SlotTypeEnum;
Chat: import("./slot").Slot.SlotTypeEnum;
};
}
我可以向 tsc 编译器添加 tsconfig 或其他提示吗?
我肯定会将 tsconfig.json 文件夹添加到您的项目根目录。并配置以下内容:
{
"include": [
"dist/typescript-angular/fes_wecare_appointment/model/*.ts"
],
"compilerOptions": {
"types": ["node"],
"outDir": "dist/node-models/fes_wecare_appointment/",
"rootDir": "dist/typescript-angular/fes_wecare_appointment/model/",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"target": "es5"
}
}
那你就运行tsc
这会让您更清楚地了解您要做什么。并且您的配置似乎有点混乱,因为包含的 ts 文件和 js 输出都在同一个 dist
目录中。并且不清楚 rootDir
选项的作用是什么?你真的想要baseUrl
吗?
此外,您最初是如何在 ts 文件中编写这些导入的?
当我 运行 tsc.exe 我最终得到指向源文件夹的导入路径。
dist/typescript-angular中的文件由swagger-codegen使用目标语言typescript-angular.
生成tsc -d --types node --target es5 --moduleResolution node --sourceMap true --experimentalDecorators --rootDir dist/typescript-angular/fes_wecare_appointment/model/ --outDir dist/node-models/fes_wecare_appointment/ dist/typescript-angular/fes_wecare_appointment/model/*.ts
我最终从源文件夹导入
export declare namespace WecareNewAppointment {
type AppointmentTypeEnum = 'video' | 'audio' | 'chat';
const AppointmentTypeEnum: {
Video: import("../../../../../../../../../Users/x/projects/x/y/dist/typescript-angular/fes_wecare_appointment/model/slot").Slot.SlotTypeEnum;
Audio: import("../../../../../../../../../Users/x/projects/x/y/dist/typescript-angular/fes_wecare_appointment/model/slot").Slot.SlotTypeEnum;
Chat: import("../../../../../../../../../Users/x/projects/x/y/dist/typescript-angular/fes_wecare_appointment/model/slot").Slot.SlotTypeEnum;
};
}
无需过多参考源文件夹中的插槽类型。它应该是这样的。
export declare namespace WecareNewAppointment {
type AppointmentTypeEnum = 'video' | 'audio' | 'chat';
const AppointmentTypeEnum: {
Video: import("./slot").Slot.SlotTypeEnum;
Audio: import("./slot").Slot.SlotTypeEnum;
Chat: import("./slot").Slot.SlotTypeEnum;
};
}
我可以向 tsc 编译器添加 tsconfig 或其他提示吗?
我肯定会将 tsconfig.json 文件夹添加到您的项目根目录。并配置以下内容:
{
"include": [
"dist/typescript-angular/fes_wecare_appointment/model/*.ts"
],
"compilerOptions": {
"types": ["node"],
"outDir": "dist/node-models/fes_wecare_appointment/",
"rootDir": "dist/typescript-angular/fes_wecare_appointment/model/",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"target": "es5"
}
}
那你就运行tsc
这会让您更清楚地了解您要做什么。并且您的配置似乎有点混乱,因为包含的 ts 文件和 js 输出都在同一个 dist
目录中。并且不清楚 rootDir
选项的作用是什么?你真的想要baseUrl
吗?
此外,您最初是如何在 ts 文件中编写这些导入的?