Typescript and Subpath Imports

Viewed 99

I am trying to get Node subpath imports and typescript to work. My IDE has no problem resolving the imports, but Typescript is never happy.

Github repo with code: https://github.com/doronrosenberg/ts-subpath-imports.

package.json:

  "imports": {
    "#internal/*": "./internal/*.ts",
    "#internal2": "./internal"
  }

tsconfig.json:

  "paths": {
    "#internal/*": "./internal/*.ts",
    "#internal2": ["./internal"]
  }

and the code:

import { foo } from "#internal/index";
import { bar } from "#internal2";

No matter how I set things up, I always get:

src/test.ts:1:21 - error TS2307: Cannot find module '#internal/index' or its corresponding type declarations.

1 import { foo } from "#internal/index";
                      ~~~~~~~~~~~~~~~~~

src/test.ts:2:21 - error TS2307: Cannot find module '#internal2' or its corresponding type declarations.

2 import { bar } from "#internal2";
                      ~~~~~~~~~~~~

Any ideas?

0 Answers
Related