Skip to content

Types-only .ts files are transformed into .d.ts files that try to import .js files #400

Description

@MasterKale

I have a package that only imports and exports TypeScript types. It has two files, index.ts and dom.ts, and index.ts relatively imports from dom.ts but not the other way around:

https://github.com/MasterKale/SimpleWebAuthn/tree/master/packages/types

I noticed recently that when my package builds, the types in these two files are being output to ${outDir}/types/ as .d.ts as expected...

Screenshot 2024-04-12 at 11 56 33 AM

...and declared in package.json as expected:

"exports": {
  ".": {
    "import": {
      "types": "./types/index.d.ts",
      "default": "./esm/index.js"
    },
    "require": {
      "types": "./types/index.d.ts",
      "default": "./script/index.js"
    }
  }
}

However when I open up ${outDir}/types/index.d.ts I see that the import type and export type statements are transformed by dnt to import from "./dom.js":

Screenshot 2024-04-12 at 11 58 56 AM

This is breaking the ability to Go To Definition on a type contained in dom.ts in libraries installing this package from NPM. I tried using mappings to replace the path, but as this isn't really what mappings is intended for of course it didn't work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions