Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent response type when using date-fns functions #39

Open
andrejtodorovski opened this issue Jan 15, 2025 · 0 comments
Open

Inconsistent response type when using date-fns functions #39

andrejtodorovski opened this issue Jan 15, 2025 · 0 comments

Comments

@andrejtodorovski
Copy link

andrejtodorovski commented Jan 15, 2025

I have these variables defined in my component:

minEndDate: TZDate | undefined;
timezone = input.required<string>();
now = computed<TZDate>(() => TZDate.tz(this.timezone()));
tomorrowsDate = computed<TZDate>(() => addDays(this.now(), 1));

now in ngOnInit() I want to assign value to minEndDate to be 1 day after the tomorrowsDate, so the following
this.minEndDate = addDays(this.tomorrowsDate(), 1);

but I get an error here TS2739: Type Date is missing the following properties from type TZDate: timeZone, withTimeZone, [constructFromSymbol], its treating the addDays(this.tomorrowsDate(), 1); as if it returns a Date.

If i assign the addDays(this.tomorrowsDate(), 1); to a variable first, for example:
const oneMoreDay = addDays(this.tomorrowsDate(), 1);
and then assign it to the minEndDate variable:
this.minEndDate = oneMoreDay
This works normally and as expected,

Do you have any idea why this is happening, is it a bug or am I doing something wrong?

The minEndDate cannot be a computed signal because I'm reassigning it later in the code, it depends on a date picker input.

I also get the correct output when doing the following:

this.minEndDate = addDays(this.tomorrowsDate(), 1, {
      in: tz(this.timezone())
    });

but I don't get it why would I need timezone information when the this.tomorrowsDate() is already a TZDate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant