TypeStrong / atom-typescript

The only TypeScript package you will ever need

Home Page:https://atom.io/packages/atom-typescript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unusual tsconfig.json location - atom-typescript can't find it!

RamoFX opened this issue · comments

Hello,

The problem

I am configuring my project (repo) and I found the best structure for my needs.
But atom-typescript package can't find my tsconfig.json, no errors when webpack compiles and bundles my code with tsconfig.json loaded.

Additional information

Atom version: 1.53.0
atom-typescript version: 14.1.2
atom-typescript settings: default, only set prefer built-in type tooltips to true

Maybe some kind of inspiration

I am working with webpack and give a tsconfig.json path to the ts-loader's options and eveything works!

Possible solutions

What I have to do to fix it? Is it a bug?

Maybe you can add some feature to auto-find tsconfig.json or make project's own tsconfig.json path?

Reproduce

  1. create tsconfig.json in /PROJECT_ROOT/frontend/configs/typescript/tsconfig.json
  2. see atom-typescript can't find tsconfig.json

Screenshots

Errors in editor

Screenshot from 2020-12-15 16-24-08

tsconfig.json

Screenshot from 2020-12-15 16-24-30

Webpack console output while dev

Screenshot from 2020-12-15 16-28-06

Any idea?

Sorry, I was busy with day job when I've seen the notification, and then I kinda forgot.

So... yeah, this is by design. The idea is, TypeScript server traverses the directory tree upwards to find tsconfig, that is, if you take a given source file, e.g. /home/user/github/awesome-project/src/client/index.ts, tsserver will look for tsconfig in /home/user/github/awesome-project/src/client/, /home/user/github/awesome-project/src/, /home/user/github/awesome-project/, /home/user/github/, etc. Obviously, upwards traversal takes linear time. Looking for tsconfig in the whole directory tree on the other hand is in worst-case scenario equivalent to enumerating all files over the whole of the filesystem. Not viable.

I mean, if you really have to, I guess you could "trick" tsserver into using a given tsconfig file. But you'd need some generic way of telling it where to look in the first place, which would boil down to having a config file in the root of the project or something similar, which defeats the purpose.

A quick hack is to add tsconfig.json at the root of the project with an extends field pointing to actual tsconfig location, e.g.

{
  "extends": "./relative/path/to/actual/tsconfig.json"
}

Thank you very much for the advice!

It would be awesome if there will be no configs in the root, but this is about how the project's structure design have been made.
I am sorry, I didn't catch that this is more Typescript server's "issue".

It's the shame, that there is no atom per-project config.
For example:

# project.atom-config.cson

'atom-typescript':
  tsconfig:
    type: 'file'
    source: '/some/path/to/the/config/tsconfig.json'