Skip to content

[@types/luxon] Validity helper types (Valid, Invalid, DefaultValidity) are not importable after the 3.7.0 export map #75462

Description

@gerbenvandijk

Affected package

@types/luxon (3.7.0 and later, reproduced on 3.7.5)

Summary

The validity helper types Valid, Invalid and DefaultValidity live in src/_util.d.ts, which is not re-exported from the barrel (src/luxon.d.ts). Before 3.7.0 they could still be reached with import type { Valid } from 'luxon/src/_util'. Since #73292 added an exports map to fix arethetypeswrong, that subpath no longer resolves, and there is now no way to name these types.

That matters because they are the type arguments of public generics: DateTime<IsValid>, Interval<IsValid>, Duration<IsValid> and Zone<IsValid> are all exported, but the values their parameter accepts are not.

Reproduction

// @types/luxon 3.7.5, luxon 3.7.2, TypeScript 5.9.3, moduleResolution: bundler
import type { DateTime } from 'luxon'
import type { DefaultValidity, Invalid, Valid } from 'luxon/src/_util'
//                                                  ^ TS2307: Cannot find module 'luxon/src/_util'
//                                                    or its corresponding type declarations.

export type Range = { start: DateTime<Valid>, end: DateTime<Valid> }

Other spellings are also closed:

  • '@types/luxon/src/_util'TS6137: Cannot import type declaration files. (and @types/luxon has its own exports map limited to . and ./package.json)
  • Suppressing with @ts-expect-error compiles, but the imported names become any, which silently degrades DateTime<Valid> | DateTime<Invalid> to a single DateTime<any> and loses the narrowing the generics exist to provide.

Workarounds that do exist

For most call sites the public API is enough, and arguably reads better:

  • DateTime<Valid>DateTime<true> (Valid is declared as true)
  • DateTime<Valid> | DateTime<Invalid> → the exported DateTimeMaybeValid
  • DateTime<DefaultValidity> → plain DateTime, since DefaultValidity is the declared default

DefaultValidity itself has no public equivalent. It can be recovered by inference:

type DefaultValidity = DateTime extends DateTime<infer V> ? V : never

but that is a workaround for a name the package could simply export.

Suggested fix

Re-export the helpers from the barrel so they are nameable, for example in src/luxon.d.ts:

export type { CanBeInvalid, DefaultValidity, IfValid, Invalid, Valid } from "./_util";

Adding "./src/*" to the exports map would also work, but re-exporting keeps the ATTW fix intact and does not expose the rest of the internals.

Happy to open a PR for whichever shape maintainers prefer.

Activity

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