kewisch/ical.js

TS types are missing from built npm package

Closed this issue ยท 7 comments

Hi ๐Ÿ‘‹๐Ÿป

When importing this library the TS types are not found:

Screenshot 2024-08-09 at 13 27 15

It seems that the TS types are not part of the packaged library artefact: https://www.npmjs.com/package/ical.js?activeTab=code

I tried to clone and build the lib locally and the types are generated just fine so the problem is probably related to the npm publishing phase.

Thanks in advance!

Actually I noticed that the generated module.d.ts file is maybe importing things from the wrong places:

import Binary from "./binary.js";
import Component from "./component.js";
import ComponentParser from "./component_parser.js";
import Duration from "./duration.js";
import Event from "./event.js";
import Period from "./period.js";
import Property from "./property.js";
import Recur from "./recur.js";
import RecurExpansion from "./recur_expansion.js";
import RecurIterator from "./recur_iterator.js";
import Time from "./time.js";
import Timezone from "./timezone.js";
import TimezoneService from "./timezone_service.js";
import UtcOffset from "./utc_offset.js";
import VCardTime from "./vcard_time.js";
import parse from "./parse.js";
import stringify from "./stringify.js";
import design from "./design.js";
import * as helpers from "./helpers.js";

Should it import from the .ts extension?

It should not be importing from the .ts extension, TypeScript writes imports with .js so the strings don't need to be transformed when transpliling.

Maybe what Temzasse is referring to how the JS files are not in /dist/types but are being referenced as relative to file in the same dir. The individual type files (e.g., helpers.d.ts) themselves reference out to the JS files "sources":["../../lib/ical/helpers.js"]

For me I'm seeing Could not find a declaration file for module './design.js'. on file imports in node_modules/ical.js/lib/ical/module.js

The types are defined only in JSDoc and need accompanying .d.ts, no?

What I find strange is that when I run jsdoc, it doesn't generate files with the expected TS declaration extension.

I merged two PRs that might have fixed this issue. Once I get a go-ahead from @jannikac I will spin a new release to make it available on npm. Could anyone having issues here try again with the latest code from main?

This fixed it for me.

Super, thanks for reporting back. @Temzasse if this is not fixed for you please feel free to reopen or file a new issue.

The types have been released as part of version 2.1.0 which is now available on npm.