Skip to content

Fix documentation that seems to imply baseUrl does something it doesn't #51267

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

Closed
RyanCavanaugh opened this issue Oct 21, 2022 · 4 comments · Fixed by microsoft/TypeScript-Website#2778
Assignees
Labels
Bug A bug in TypeScript Docs The issue relates to how you learn TypeScript Help Wanted You can do this
Milestone

Comments

@RyanCavanaugh
Copy link
Member

    > If you get tired of imports always looking like "../" or "./", or needing to change them as you move files, this is a great way to fix that.

This text is one of my biggest pet peeves in the documentation. It's described as if it's some convenience feature that TS will take care of for you, but in reality it only works if your runtime environment also understands it, because TS emits the import paths you use verbatim.

Originally posted by @fatcerberus in #51260 (comment)

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this Docs The issue relates to how you learn TypeScript labels Oct 21, 2022
@RyanCavanaugh RyanCavanaugh changed the title Fix documentation that seems to imply paths does something it doesn't Fix documentation that seems to imply baseUrl does something it doesn't Oct 21, 2022
@fatcerberus
Copy link

There are similar implications in the docs for paths, for what it’s worth.

@MAYANKpandey14
Copy link

I think it implies creating a tsconfig.json file with the following contents:

  "compilerOptions": {
    "baseUrl": "./modules"
  }
}

So if a module is imported such as navBar it would be looked up in ./modules/navBar
import A from navBar

Although, what you are pointing out is correct and the use of baseURL can be explained more precisely and not in a way it is done already.

Screenshot 2022-12-22 at 11 37 32 PM

@andrewbranch
Copy link
Member

Why does baseUrl actually exist? Today, it could legitimately be useful for doing ESM in the browser, though we lack nearly every other option necessary to support that scenario. But I’m pretty sure baseUrl was made long before ESM in the browser was possible, or even a definite future. Was it made to pair with AMD?

@RyanCavanaugh
Copy link
Member Author

Right, it's named after the RequireJS option which kinda does the same thing: https://requirejs.org/docs/api.html#config-baseUrl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Docs The issue relates to how you learn TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants