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.
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
export class Review {
_id: number;
description: string;
isComplete: boolean;
}
Use named exports to export multiple classes in TypeScript, e.g. export class A {} and export class B {} . The exported classes can be imported by using a named import as import {A, B} from './another-file' . You can have as many named exports as necessary in a file.
To import a function from another file in TypeScript: Export the function from file A , e.g. export function sum() {} . Import the function in file B as import { sum } from './another-file' . Use the imported function in file B .
In typescript by using an import statement, a module can be utilized in another module. any variables, classes, methods, or other objects declared in a module are not accessible outside of it. The keyword “export” may be used to construct a module, and the term “import” can be used to import it into another module.
TypeScript uses the concept of modules, in the same way that JavaScript does. In order to be able to import an interface from a different file, it has to be exported using a named or default export.
import {Review} from '../app/review'
instead of
import {Review} from '../app/review.ts'
That's all :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With