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

Luxon DateTime is not assignable to type ICalDateTimeValue in Typescript #482

Closed
ismarslomic opened this issue Apr 22, 2023 · 3 comments
Closed

Comments

@ismarslomic
Copy link

When I'm trying to assign an Luxon DateTime to the start and end properties of the ICalEvent (Typescript) I get following error message in IntelliJ and tsc:

index.ts:9:5 - error TS2322: Type 'DateTime' is not assignable to type '{ (): ICalDateTimeValue | null; (start: ICalDateTimeValue): ICalEvent; } | ICalDateTimeValue | null | undefined'.
  Type 'DateTime' is not assignable to type 'ICalLuxonDateTimeStub'.
    The types returned by 'toJSON()' are incompatible between these types.
      Type 'string | null' is not assignable to type 'string'.
        Type 'null' is not assignable to type 'string'.

9     start: startTime,
      ~~~~~

  node_modules/ical-generator/dist/index.d.cts:951:5
    951     start(): ICalDateTimeValue | null;
            ~~~~~
    The expected type comes from property 'start' which is declared here on type 'ICalEvent | ICalEventData'

index.ts:10:5 - error TS2322: Type 'DateTime' is not assignable to type 'ICalDateTimeValue | { (): ICalDateTimeValue | null; (end: ICalDateTimeValue | null): ICalEvent; } | null | undefined'.
  Type 'DateTime' is not assignable to type 'ICalLuxonDateTimeStub'.

10     end: endTime,
       ~~~

  node_modules/ical-generator/dist/index.d.cts:967:5
    967     end(): ICalDateTimeValue | null;
            ~~~
    The expected type comes from property 'end' which is declared here on type 'ICalEvent | ICalEventData'

Here is the setup to reproduce the issue:

package.json

{
  "name": "ical-hello-world",
  "version": "1.0.0",
  "devDependencies": {
    "@tsconfig/node18": "^2.0.0",
    "@types/luxon": "^3.3.0",
    "@types/node": "^18.15.13",
    "typescript": "^5.0.4"
  },
  "scripts": {
    "build": "tsc"
  },
  "dependencies": {
    "ical-generator": "^4.0.0",
    "luxon": "^3.3.0"
  }
}

tsconfig.json

{
  "extends": "@tsconfig/node18/tsconfig.json"
}

index.ts

import ical, {ICalCalendar} from 'ical-generator';
import {DateTime} from "luxon";

const calendar:ICalCalendar = ical({name: 'my first iCal'});
const startTime: DateTime = DateTime.now();
const endTime: DateTime = DateTime.now();

calendar.createEvent({
    start: startTime,
    end: endTime,
    summary: 'Example Event',
    description: 'It works ;)',
    location: 'my room',
    url: 'http://sebbo.net/'
});
@ismarslomic ismarslomic changed the title Luxon DateTime is not assignable to type ICalDateTimeValue Luxon DateTime is not assignable to type ICalDateTimeValue in Typescript Apr 22, 2023
@ismarslomic
Copy link
Author

I recognised that this is caused by the strict type checking that is by default enabled in the tsconfig bases for node18. By overriding the strict flag to false I don't get the errors anymore.

Updated tsconfig.json

{
  "extends": "@tsconfig/node18/tsconfig.json",
  "compilerOptions": {
    "strict": false,
  }
}

@sebbo2002 sebbo2002 mentioned this issue May 2, 2023
github-actions bot pushed a commit that referenced this issue May 2, 2023
# [4.1.0-develop.3](v4.1.0-develop.2...v4.1.0-develop.3) (2023-05-02)

### Bug Fixes

* Allow `null` return value for Luxon 3.3's DateTime.toJSON() ([bee19a8](bee19a8)), closes [#482](#482) [#485](#485)
@sebbo2002
Copy link
Owner

🎉 This issue has been resolved in version 4.1.0-develop.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit that referenced this issue May 4, 2023
# [4.1.0](v4.0.0...v4.1.0) (2023-05-04)

### Bug Fixes

* Allow `null` return value for Luxon 3.3's DateTime.toJSON() ([bee19a8](bee19a8)), closes [#482](#482) [#485](#485)
* revent changes to package.json version ([916e460](916e460))
* revert package-lock.json ([a8d8f2d](a8d8f2d))

### Features

* Support trigger related behavior ([54743df](54743df))
@sebbo2002
Copy link
Owner

🎉 This issue has been resolved in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants