sublimelsp / LSP-typescript

TypeScript, JavaScript support for Sublime LSP plugin
MIT License
131 stars 11 forks source link

Typescript seems to compile fine even when plugin says otherwise. #215

Closed callenAUS closed 1 year ago

callenAUS commented 1 year ago

I have a Node/Express project with static JS files inside. Due to this I have 2 tsconfig files in a folder at the root directory. I think this might be the root cause.

Compiling with npx "tsc" "--project" "./tsconfigs/browser.json" works without issue. However the plugin seems to have issues with me switching my imports from relative to absolute paths.

The specific error that is thrown in sublime is Cannot find module '/js/lib/example.js' or its corresponding type declarations.

browser.json

{
    "include": ["../src/static/**/*"],
    "exclude": [],
    "compilerOptions": {
        "target": "ES2020",
        "baseUrl": "../src/static/",
        "rootDir": "../src/static/",
        "outDir": "../build/static/",
        "esModuleInterop": true,
        "strict": true,
        "module": "ES2020",
        "types": [],
        "paths": {
            "/*": ["*"],
        }
    }
}

node.json

{
    "include": ["../src/**/*"],
    "exclude": ["../src/static/**/*"],
    "compilerOptions": {
        "target": "ES2020",
        "rootDir": "../src/",
        "outDir": "../build/",
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "noImplicitAny": true,
        "noImplicitThis": true,
        "noImplicitReturns": true,
        "noImplicitOverride": true,
        "module": "commonjs",
        "types": ["node", "express"],
        "moduleResolution": "node",
    }
}
predragnikolic commented 1 year ago

Hello,

The tsserver needs to support that.

There was this open issue for typescript: https://github.com/microsoft/TypeScript/issues/11224

They decided to not implement it https://github.com/microsoft/TypeScript/issues/11224#issuecomment-250595304

But that should not be a blocker for you.

The current workaround is to have a tsconfig.json file at the root and specify the extends. https://github.com/microsoft/vscode/issues/18140#issuecomment-270589109

Also know that since typescript v5.0 the tsconfig.extends accepts an array. https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#supporting-multiple-configuration-files-in-extends

I will choose the issue, because there is nothing that LSP-typescript can do about it.