使用 Typescript 导入类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42932935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Importing a class with Typescript
提问by Smurfffy
I'm trying to import a class called review I have from another typescript file called review.ts into my review-service.ts file however I don't know why I'm getting an error but I don't think the review.ts file I have is being imported properly into the review-service.ts file.
我正在尝试将另一个名为 review.ts 的打字稿文件中的一个名为 review 的类导入到我的 review-service.ts 文件中,但是我不知道为什么会出现错误,但我不认为是。我拥有的 .ts 文件正在正确导入到 review-service.ts 文件中。
The image below is the file with the error which outlines the path of the file I'm trying to import from and the file structure of the app
下图是带有错误的文件,它概述了我尝试从中导入的文件的路径以及应用程序的文件结构
Also in another screenshot I have it shows the "module" for the path is coming up as *. I have no idea why this is an I've tried many different paths to try get this to work.
同样在另一个屏幕截图中,我显示路径的“模块”以 *. 我不知道为什么这是一个我尝试了很多不同的路径来尝试让它工作。
The constents of review.ts are as follows
review.ts 的内容如下
//review.ts
export class Review {
_id: number;
description: string;
isComplete: boolean;
}
回答by Mateusz Szymik
import {Review} from '../app/review'
instead of
代替
import {Review} from '../app/review.ts'
That's all :)
就这样 :)