将 class 个模块导入另一个 class
Importing class modules into another class
我正在尝试将一些 classes 导入到我的主 class 中,但是出现错误;未捕获的语法错误:导入 ApiDto = Model.DtoModel.ApiDto;
行出现意外的令牌导入
有两个 DTO 模型在两个文件中共享相同的模块名称;
export module DtoModel {
export class ApiDto {
}
export class ApiDtoItem {
public method: string;
public object: any;
}
}
export module DtoModel {
export class User {
public userNo: number;
}
}
这是项目结构;
Main.ts
/// <reference path="jquery.d.ts" />
import * as Model from "../DtoModels/./ApiDto";
// breaks on next line!
import ApiDto = Model.DtoModel.ApiDto;
export class Main {
private Url: string;
constructor() {
var apidto = new ApiDto();
this.Url = "http://localhost:80/api/main";
var response = jQuery.post(this.Url, (data: ApiDto, textStatus: string, jqXHR: JQueryXHR) => {
apidto = data;
});
console.log(response);
}
}
var main: Main = new Main();
这是我的编译选项:
{
"compilerOptions": {
"target": "es6",
"noImplicitAny": true,
"noEmitOnError": false,
"sourceMap": true,
"inlineSources": true
},
"compileOnSave": true
}
您正在将打字稿编译为 ES6("target": "es6"
in tsconfig.json)。但是浏览器本身并不支持 ES6 imports/exports - 因此出现错误。
我正在尝试将一些 classes 导入到我的主 class 中,但是出现错误;未捕获的语法错误:导入 ApiDto = Model.DtoModel.ApiDto;
行出现意外的令牌导入有两个 DTO 模型在两个文件中共享相同的模块名称;
export module DtoModel {
export class ApiDto {
}
export class ApiDtoItem {
public method: string;
public object: any;
}
}
export module DtoModel {
export class User {
public userNo: number;
}
}
这是项目结构;
Main.ts
/// <reference path="jquery.d.ts" />
import * as Model from "../DtoModels/./ApiDto";
// breaks on next line!
import ApiDto = Model.DtoModel.ApiDto;
export class Main {
private Url: string;
constructor() {
var apidto = new ApiDto();
this.Url = "http://localhost:80/api/main";
var response = jQuery.post(this.Url, (data: ApiDto, textStatus: string, jqXHR: JQueryXHR) => {
apidto = data;
});
console.log(response);
}
}
var main: Main = new Main();
这是我的编译选项:
{
"compilerOptions": {
"target": "es6",
"noImplicitAny": true,
"noEmitOnError": false,
"sourceMap": true,
"inlineSources": true
},
"compileOnSave": true
}
您正在将打字稿编译为 ES6("target": "es6"
in tsconfig.json)。但是浏览器本身并不支持 ES6 imports/exports - 因此出现错误。