microsoft/typescript-go

Complains about relative paths in `"paths"` but this works fine in current tsc

Closed this issue · 9 comments

Hey,
Decided to give the holy grail 10x typescript perf a go!
It won't compile my project tsgo -p tsconfig.json

Steps to reproduce

{
  "compilerOptions": {
    "lib": ["ES2022", "DOM", "DOM.Iterable"],
    "module": "ES2022",
    "target": "ES2022",
    "rootDir": "./",
    "outDir": "./built",
    "baseUrl": "./",
    "allowJs": false,
    "checkJs": false,
    "alwaysStrict": true,
    "noImplicitAny": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noEmitOnError": false,
    "sourceMap": true,
    "declaration": true,
    "esModuleInterop": true,
    "noImplicitOverride": true,
    "noUncheckedIndexedAccess": true,
    "incremental": false,
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "removeComments": true,
    "moduleResolution": "Bundler",
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "paths": {
      "lib": ["lib"],
      "types": ["types"],
      "test": ["test"]
    },
    "verbatimModuleSyntax": true,
    "moduleDetection": "force"
  },
  "include": [
    "types/**/*.ts",
    "lib/**/*.ts",
    "test/**/*.ts",
    "examples/**/*.ts",
    "scripts/**/*.ts",
    "migrations/**/*.ts",
    "tools/**/*.ts",
    "k6/**/*.ts"
  ],
  "exclude": ["node_modules/**/*"]
}

Behavior with typescript@5.8

Compiles fine

Behavior with tsgo

I get the error:

tsconfig.json:36:15 - error TS5090: Non-relative paths are not allowed. Did you forget a leading './'?

36       "lib": ["lib"],
                 ~~~~~

However if i change that to ./lib I get:

test/unit/modules/services/store.test.ts:5:25 - error TS2307: Cannot find module 'lib/modules/references/dto' or its corresponding type declarations.

5 import { RefUser } from 'lib/modules/references/dto'

Without a repo, I don't think we can really guess at what's going on here too much.

I guess it's odd that the old TS didn't mind the missing ./? Does old TS work when the ./ is added?

OK https://github.com/Stono/typescript-go-1713

If you do npm run build-tsc, it compiles fine (run node built/lib/a.js).
If you do npm run build-tsgo, it doesn't compile, and I can't find any permutation of baseUrl and paths configuration to make it compile.

Remove baseUrl, then do:

"paths": {
  "lib/*": ["./lib/*"]
}

The only reason your original code works is becuase "baseUrl": "." is effectively the same as writing:

"paths": {
  "*": ["./*"]
}

The original code still errors in tsc with:

tsconfig.json:33:15 - error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?

33       "lib": ["lib"],
                 ~~~~~

tsconfig.json:34:17 - error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?

34       "types": ["types"],
                   ~~~~~~~

tsconfig.json:35:16 - error TS5090: Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?

35       "test": ["test"]
                  ~~~~~~

So isn't right either; I'm not sure why you'd have seen it compiling fine in 5.8 as noted in the issue.

Image

Certainly compiles fine for me!

Either way, the change you suggested does work, and I got one of my apps to compile using tsgo!

I guess old tsc joined the paths with baseUrl, which papers over this issue. tsgo doesn't touch baseUrl at all, so doesn't, leading to extra errors.

In any case, that's intentional.

Will close then, cheers for your help

I guess old tsc joined the paths with baseUrl, which papers over this issue. tsgo doesn't touch baseUrl at all, so doesn't, leading to extra errors.

In any case, that's intentional.

Hey Jake! Sorry to comment on a closed issue, but just wanted to clarify what you're saying... You're saying tsgo needs different paths than tsc if using a basePath? For example, if I have a "basePath": "./src", then tsgo would need something like "paths": { "somePath": "./src/somePath" }, while tsc would just be "paths": { "somePath": "./somePath" }?

That is my understanding, but many months on now it's probably better for you to just use Andrew's tool to do this: microsoft/TypeScript#62508 (comment)