Skip to content

publishing deep-dive is out of date regarding "exports" #3088

Open

Description

Page URL: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html

publishing.html mentions "types" and "typings" fields but there are no comments about "exports" which I believe can supersede those. And I think they do not apply when there is a subpath based on documentation from https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-main-and-types.

https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports has good information about resolving; so, one could work backward if just given a reference there. But specific guidance on authoring is probably best.

"typings" is listed as an alias on publishing.html but is noted as legacy on modules/reference.html.

Activity

  1. changed the title [-]publisihng deep-dive is out of date regarding "exports"[/-] [+]publishing deep-dive is out of date regarding "exports"[/+] on May 5, 2024
  2. agilgur5 commented on Mar 24, 2025

    @agilgur5
    Contributor

    The lack of updates on this page is indeed very confusing for library developers. Just ran into this issue twice in taybenlor/runno#324 and agilgur5/react-signature-canvas#126.

    but there are no comments about "exports" which I believe can supersede those. And I think they do not apply when there is a subpath based on documentation from https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-main-and-types.

    Indeed, if you have exports, you must define types inside of exports (e.g. exports.types). Per TS maintainers in microsoft/TypeScript#52363 (comment) and microsoft/TypeScript#46334, TS will not fallback to the top-level types when exports is defined. Those maintainer comments have been referenced a lot and are buried in TS issues -- there really should be clear, direct, official guidance in the official docs.
    One of the maintainers also created https://github.com/arethetypeswrong/arethetypeswrong.github.io as a website and CLI to diagnose this -- would be nice to add that to the docs too.

    There are also some docs buried in the 4.7 release notes.

    Matching the intent of the "Publishing" page, I think specific, centralized publishing guidance would be better and would significantly reduce confusion.

    "typings" is listed as an alias on publishing.html but is noted as legacy on modules/reference.html.

    I tested this and typings does not work inside of exports. You cannot use exports.typings and must use exports.types (or deeper structures -- the naming is the key difference, literally).
    As such, for consistency and less mistakes, it would make sense to migrate top-level typings to types as well and only mention this as a legacy alias that should not be used moving forward.

  3. MartinFerret commented on Nov 14, 2026

    @MartinFerret

    I'd like to pick this up, building on Anton Gilgur (@agilgur5)'s notes above.

    My plan for Publishing.md:

    • a short section on "exports", showing the "types" condition listed first for each subpath, and that under node16, nodenext and bundler resolution TypeScript doesn't fall back to the top-level "types" for paths that "exports" covers
    • "typings" presented as a legacy field that doesn't work as a condition inside "exports"
    • links to the modules reference, the 4.7 release notes and arethetypeswrong

    WDYT?

  4. jason-ha commented on Nov 16, 2026

    @jason-ha
    Author

    Updated, docs? Yes, please.
    I think the note that "types" is required is mistaken, though. TypeScript, in my experience, will look for a .d.ts in same location as .js when "types" condition isn't resolved first. It is nice simplification for package authors to just specify the runtime .js path for exports entry when .d.ts is expected sibling rather than necessarily having "types" qualification.

  5. MartinFerret commented on Nov 16, 2026

    @MartinFerret

    Ah, good catch, you're right! If the .d.ts sits right next to the .js, TypeScript finds it on its own, so "types" is only needed when the declarations live somewhere else.

    I'll make that clear in the docs. Thanks!

  6. MartinFerret commented on Nov 26, 2026

    @MartinFerret

    #3708 covers this now, so I'll step back. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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