Answer the question
In order to leave comments, you need to log in
Typescript - how to correctly set aliases for modules?
Playing with Angular and Typescript.
There is a scripts/ folder which contains the main component of Angular, as well as the Services/ and Components/ folders.
The Services/ and Components/ folders contain services and directives, respectively.
Now, in order for me to import a service from a component, I have to import along the view path
import { SomeService } from '../../Services/SomeService';
import { SomeService } from 'services';
declare module 'services' {
export { FileUploadService } from './Services/FileUploadService';
export { RedirectService } from './Services/RedirectService';
}
resources/assets/typescript/components.d.ts(2,5): error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
resources/assets/typescript/components.d.ts(3,5): error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
resources/assets/typescript/components.d.ts(3,33): error TS2307: Cannot find module './Components/UI/ProgressBar/ProgressBar'.
resources/assets/typescript/services.d.ts(2,5): error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
resources/assets/typescript/services.d.ts(2,39): error TS2307: Cannot find module './Services/FileUploadService'.
resources/assets/typescript/services.d.ts(3,5): error TS2439: Import or export declaration in an ambient module declaration cannot reference module through relative module name.
resources/assets/typescript/services.d.ts(3,37): error TS2307: Cannot find module './Services/RedirectService'.
Answer the question
In order to leave comments, you need to log in
Well, if you load and assemble ts using SystemJS, then you can make as many aliases as you like there. If tsc, then there seems to be no such thing.
If tsc is used, then baseUrl: “src/“ can be set in tsconfig.json and then imports like
import foo from “components/foo” will be available.
The components folder is located in src
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question