TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Add {root} helper for tsconfig.json (for avoiding multiple ../../)

Open Yegorich555 opened this issue 4 years ago • 3 comments

Search Terms

helper {root} {workspace} in tsconfig.json

Suggestion

I have the following project structure

tsconfig.json
>folder
   >folder
     >folder
       tsconfig.json => 
         {
             "extends": "../../../tsconfig.json"
              ... 
         }

I didn't find any path-helper that can replace "../../../" to {root} where the root is the current workspace folder

Use Cases

Avoiding using "../../../" because of this is a headache for refactoring

Examples

// folder/folder/folder/tsconfig.json
{
  "extends": "{rootOrWorkspaceFolder}/tsconfig.json"
   "paths": {
      "root/*": ["{rootOrWorkspaceFolder}/*"]
    }
}

Checklist

My suggestion meets these guidelines:

  • [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ ] This wouldn't change the runtime behavior of existing JavaScript code
  • [x] This could be implemented without emitting different JS based on the types of expressions
  • [ ] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [ ] This feature would agree with the rest of TypeScript's Design Goals.

Yegorich555 avatar Mar 05 '20 08:03 Yegorich555

What is the "current workspace folder"? How is that determined?

MartinJohns avatar Mar 05 '20 17:03 MartinJohns

  • process.cwd() in NodeJs...
  • package.json can point on the workspace folder. It always in the root

A lot of packages use similar logic for defining {root} (jest for example)

Yegorich555 avatar Mar 05 '20 20:03 Yegorich555

I guess this is pretty similar to my new issue https://github.com/microsoft/TypeScript/issues/51213, wonder if I should close 51213 in favor of this... (or the other way around)

karlhorky avatar Oct 18 '22 15:10 karlhorky