Closed karlhorky closed 1 year ago
Thanks for this great bug report. Unfortunately, I don't see at first glance why the type definitions are being generated incorrectly and since I have a visitor this weekend, I probably won't be able to deal with it extensively until next week. I hope that's ok, otherwise pull requests are always appreciated of course. Thank you.
Also not 100% sure what tsconfig.json
options cause this, but if I would have to guess, I would look at this compilerOptions.target: 'es6'
- seems like an outdated module format. Also module: 'none'
is interesting... π€
Maybe the compilerOptions.target
is actually fine and module: "commonjs"
is needed, as per this Stack Overflow answer?
Do you want to try it with the current develop version (ical-generator@4.0.0-develop.1
)?
Forked the StackBlitz demo to a new one, seems like it's working π
Thanks! Closing this.
Updated (working) StackBlitz demo: https://stackblitz.com/edit/node-5l65bv?file=tsconfig.json,package.json&file=tsconfig.json,index.ts
@sebbo2002 reopening this - ical-generator@4.0.0-develop.2
is broken again:
StackBlitz Demo: https://stackblitz.com/edit/node-rrwxxe?file=package.json&file=index.ts
Also check it out on Are The Types Wrong?
Yes, I've seen when merged it in, but I don't understand the error yet and I haven't had time to look at it. The .d.ts
file is the same, yes, but I only have one type definition file after running tsup
. If I duplicate the file so that the filenames are different, everything is okay. But that can't possibly be the cause.
Haven't looked at your project configuration / publishing formats yet, but maybe you need *.d.mts
files like this?
That's what I meant with duplicating the file. Okay. I will play around a bit more on the weekend, feel free to use the develop.1
for this time. I'll update the ticket here when I think I'm done with customizations π
Yeah the *.d.mts
files seemed counterintuitive to me at first too, but Andrew Branch suggested them when I was doing some other PRs fixing types in libraries, so I think it's a good way to go.
Fixed with π 4.0.0
Great, thanks so much for this! π
I can confirm that it's working - just upgraded to ical-generator@4.0.0
in our project ical-move-events
and it works π
I would have a question: how did you get the compiler to emit the dist/index.d.cts
file?
Was it just this change to the tsconfig.json
in https://github.com/sebbo2002/ical-generator/pull/462?
- "module": "none",
- "moduleResolution": "node",
+ "module": "nodenext",
+ "moduleResolution": "nodenext",
I'd like to learn how you did it to be able to recommend things for other packages too...
If you have any other changes that should be highlighted, happy to hear about those too!
Oh wait, maybe it's this manual cp
that you did in package.json
? π€
- "build": "tsc",
+ "build": "tsup && cp ./dist/index.d.ts ./dist/index.d.cts",
I thought there would have been a way for tsc
to create these files automatically π―
Yep, it's the manual cp
. Directly with tsc
or tsup
I did not find a way to create the *.d.cts
file. Specifying the same file in package.json
generates the "Masquerading as CJS" error message, symlinks don't work unfortunately. Whereby I am honestly unsure if "Masquerading as CJS" is really an issue. But this way it works in any case, even if it is a bit messy with the cp
.
Yeah, any issue in Are The Types Wrong? is an issue, any "Masquerading as ..." error is going to cause the same type of errors when import
ing / require
ing that I reported.
Thanks for the tip with cp
! If I see anything else better (or find a way to do it in tsc
), I'll try to report back here! Would love to be able to make this as zero-config and easy for lib authors / maintainers as possible!
@sebbo2002 It seems that this currently does not work for "node16" in tsconfig.json with Node v20.9.0 and v20.11.1
import ical from "ical-generator";
const cal = ical();
Error:
src/index.ts(13,15): error TS2349: This expression is not callable.
Type 'typeof import("/project/workspace/node_modules/ical-generator/dist/index")' has no call signatures.
Reproduction example: https://codesandbox.io/p/devbox/simple-express-server-forked-vvg49x?file=%2Fpackage.json%3A14%2C26
//tsconfig.json
"compilerOptions": {
"target": "ES2022",
"module": "Node16"
"moduleResolution": "Node16",
Option 1:
// Use the calendar item class directly:
import { ICalCalendar } from "ical-generator";
const calendar = new ICalCalendar();
console.log(calendar);
// This works without any problems
Option 2: Add a named export to the ical-generator package for ical.
// src/index.ts in ical-generator
- function ical(data?: ICalCalendarData): ICalCalendar {
+ export function ical(data?: ICalCalendarData): ICalCalendar {
return new ICalCalendar(data);
}
export default ical;
// usage:
import { ical } from "ical-generator";
It could be that it is related to this: https://github.com/microsoft/TypeScript/issues/50175
Hi @sebbo2002 π Thanks again for
ical-generator
, very useful!The new module resolution option
node16
does not work withical-generator
unfortunately, failing with theThis expression is not callable
error:StackBlitz demo: https://stackblitz.com/edit/node-mmyw9w?file=tsconfig.json,package.json&file=tsconfig.json,index.ts
The problem is the
export default
in the publishedindex.d.ts
, as far as I understand, sinceical-generator
uses a CommonJSmodule.exports =
export, this should actually instead beexport =
.You can also see this on the tool Are The Types Wrong from @andrewbranch: