[@types/luxon] Validity helper types (Valid, Invalid, DefaultValidity) are not importable after the 3.7.0 export map
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/luxonhas its ownexportsmap limited to.and./package.json)- Suppressing with
@ts-expect-errorcompiles, but the imported names becomeany, which silently degradesDateTime<Valid> | DateTime<Invalid>to a singleDateTime<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>(Validis declared astrue)DateTime<Valid> | DateTime<Invalid>→ the exportedDateTimeMaybeValidDateTime<DefaultValidity>→ plainDateTime, sinceDefaultValidityis the declared default
DefaultValidity itself has no public equivalent. It can be recovered by inference:
type DefaultValidity = DateTime extends DateTime<infer V> ? V : neverbut 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.
Source: DefinitelyTyped/DefinitelyTyped