Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to import modules through absolute paths? or is something like that planned? #5239

Closed
iam3yal opened this issue Oct 13, 2015 · 2 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@iam3yal
Copy link

iam3yal commented Oct 13, 2015

Currently when referring to modules I think that you must use relative paths.
For complex structures it's not convenient for example, say we have the following project structure.

R
|-- A
|   |
|   `-- a.ts
|-- B
|   |
|   `-- b.ts
|
|-- c.ts
|
`-- tsconfig.json

Now let's say that module B depends on A so currently we would have to use relative paths like so:

// b.ts
import {A} from "../A/a.ts"

export class B {
}

I gave simplistic example but it can easily turn into more complex structure if I was nesting it a bit more.

What I would like to do instead is as follow:

// b.ts
import {A} from "./A/a.ts"

export class B {
}

Basically what I'm suggesting is to resolve the dependency from the root where the root can either be specified to the compiler or otherwise starts from the tsconfig.json file.

Maybe you can borrow the symbol from ASP.NET where they use tilde to refer to the application root like so:

// b.ts
import {A} from "~/A/a.ts"

export class B {
}

Resolving the dependencies from the root feels more robust and reads a lot better when dealing with nested dependencies.

@jbrantly
Copy link

Related: #5039

@iam3yal
Copy link
Author

iam3yal commented Oct 13, 2015

@jbrantly thanks mate!

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Oct 21, 2015
@mhegazy mhegazy closed this as completed Oct 21, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants