timocov / dts-bundle-generator

A tool to generate a single bundle of dts with types tree-shaking
MIT License
762 stars 40 forks source link

[9.4.0] A definition being referenced is lacking #318

Closed Shin-Ogata closed 6 months ago

Shin-Ogata commented 6 months ago

Bug report Thank you for the great job. Since v9.4.0, there is an issue where definitions referenced are lacking and then the generated file is not correct. When using v9.3.1, the equivalent of Expected output is output. (In this report, the definition of $StringKeyPathToRecordUnion is missing.)

Input code

type $StringKeyPathToRecordUnion< TPath extends string, TValue,

= TPath extends ${infer TKey}.${infer Rest} ? { [Key in TKey]: $StringKeyPathToRecord<Rest, TValue> } : { [Key in TPath]: TValue };

export type $StringKeyPathToRecord<TPath extends string, TValue> = $UnionToIntersection< $StringKeyPathToRecordUnion<TPath, TValue>

;

Expected output

export type $UnionToIntersection<T> = (T extends unknown ? (k: T) => void : never) extends (k: infer I) => void ? I : never;
export type $StringKeyPathToRecordUnion<TPath extends string, TValue> = TPath extends `${infer TKey}.${infer Rest}` ? {
    [Key in TKey]: $StringKeyPathToRecord<Rest, TValue>;
} : {
    [Key in TPath]: TValue;
};
export type $StringKeyPathToRecord<TPath extends string, TValue> = $UnionToIntersection<$StringKeyPathToRecordUnion<TPath, TValue>>;
export type Test = $StringKeyPathToRecord<"test", unknown>;

export {};

Actual output

export type $UnionToIntersection<T> = (T extends unknown ? (k: T) => void : never) extends (k: infer I) => void ? I : never;
export type $StringKeyPathToRecord<TPath extends string, TValue> = $UnionToIntersection<$StringKeyPathToRecordUnion<TPath, TValue>>;
export type Test = $StringKeyPathToRecord<"test", unknown>;

export {};

Error Report N/A. Here is the output using verbose:

> dts-bundle-generator --config ./config.json --verbose

Verbose log enabled
Trying to load config from ./config.json file...
Total entries count=1
Compiling input files...
Using config: tsconfig.json
Skipping compiling the project to generate d.ts because all files in it are d.ts already
Processing types/index.d.ts
======= Processing C:/Users/shin/Projects/GitHub/PR/dts-bundle-generator-lack-defs/types/helper.d.ts =======
======= Processing types/index.d.ts =======
Writing types/index.d.ts -> dist/bundle.d.ts
File checking is skipped (due nothing to check)
Done in 0.65s

How to reproduce the issue

Environment

OS: Windows 10
NodeJS: v20.9.0
npm: v10.1.0
typescript: v5.4.5
dts-bundle-generator: v9.4.0
timocov commented 6 months ago

Broken by 7252a359fd11420be798b2ecb5f2d28258dd8c8b

timocov commented 6 months ago

Thanks for reporting the issue! The fix has been deployed in v9.4.1.

alex-kinokon commented 6 months ago

FYI this fix has a significant overhead that can cause a 4.4x slow down (4.8s → 22s).

timocov commented 6 months ago

@alex-kinokon do you have a repro that I can use to verify a proper fix will work well? If you don't mind, please cut a ticket so we can track it and fix separately.

alex-kinokon commented 6 months ago

@timocov https://github.com/alex-kinokon/reprod: modify the version dts-bundle-generator to 9.4.0 to see the yarn build time to decrease from 14s to 9s.

timocov commented 6 months ago

@alex-kinokon thanks! I created #322 to investigate possible solution.