date-fns: 3.0.0-alpha.2, format cannot be used as value
I installed date-fns and it installed the alpha version by default, I haven’t seen this reported before so here it is
import { format } from 'date-fns';
const createdAt = project.createdAt ? format(project.createdAt.toDate(), 'PP') : 'N/A';
Which gives me the following error 'format' cannot be used as a value because it was exported using 'export type'.
The format is exported as export declare function format<DateType extends Date>(date: DateType | number | string, formatStr: string, options?: FormatOptions): string;
typescript 5.3.2 with date-fns 3.0.0-alpha.2
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Reactions: 27
- Comments: 18 (4 by maintainers)
Same problem on the release 3.0.0
If you change
to
in
index.d.mtsthe error goes away 🤔Similar of course would need to be done to all entry files.
+1 waiting for fix
I shipped with the fix with
date-fns@3.0.1, please try itYeah but you lose tree-shaking, so its only a temporary solution 😕 @FedericoBiccheddu
Thank you for the fix and your work. Very much appreciated 🙏
I updated the package and it worked fine. Thanks a lot!
https://github.com/Sailwayfun/date-fns-format.git
This is a newly set up React + Vite + Typescript project, where you can see Typescript complains about the “format” function.
Same problem with
date-fns@3.0.0-rc.2andtypescript@5.3.3.It resolves correctly if using: