Ciantic
Ciantic2y ago

Date-fns typings don't work?

I'm trying this code:
import { startOfDay } from "https://esm.sh/date-fns@2.29.3";

// No error?
let foo = startOfDay("foo");
import { startOfDay } from "https://esm.sh/date-fns@2.29.3";

// No error?
let foo = startOfDay("foo");
I can see that they use declare module in their typings file, is this causing the issue?
3 Replies
Ciantic
CianticOP2y ago
I also tried this: https://cdn.skypack.dev/date-fns?dts as import, but it too doesn't give right types Interestingly this works:
import { startOfDay } from "npm:date-fns";

// Gives out Error CORRECTLY
let foo = startOfDay("foo");
import { startOfDay } from "npm:date-fns";

// Gives out Error CORRECTLY
let foo = startOfDay("foo");
ioB
ioB2y ago
probably a cdn issue compat mode should more accurately run npm modules
Ciantic
CianticOP2y ago
I think it's issue with their typings.d.ts it uses declare module:
declare module 'date-fns' {
export type Interval = IntervalAliased

export type Locale = LocaleAliased

export type Duration = DurationAliased

export type Day = DayAliased
}

// Regular Functions

declare module 'date-fns' {
function add(date: Date | number, duration: Duration): Date
namespace add {}

function addBusinessDays(date: Date | number, amount: number): Date
namespace addBusinessDays {}
//...
declare module 'date-fns' {
export type Interval = IntervalAliased

export type Locale = LocaleAliased

export type Duration = DurationAliased

export type Day = DayAliased
}

// Regular Functions

declare module 'date-fns' {
function add(date: Date | number, duration: Duration): Date
namespace add {}

function addBusinessDays(date: Date | number, amount: number): Date
namespace addBusinessDays {}
//...
Somehow deno and esm.sh can't understand that. there is also some weird namespace involved for each function