unbuild
unbuild copied to clipboard
types inside .d.ts files are bugged
Environment
"unbuild": "^2.0.0",
$ node --version
v20.9.0
Reproduction
If you use unbuild on the following code:
/* eslint-disable @typescript-eslint/no-explicit-any */
interface ReadonlyMapConstructor {
new (): ReadonlyMap<any, any>;
new <K, V>(
entries?: ReadonlyArray<readonly [K, V]> | Iterable<readonly [K, V]> | null,
): ReadonlyMap<K, V>;
readonly prototype: ReadonlyMap<any, any>;
}
/** An alias for the `Map` constructor that returns a read-only map. */
export const ReadonlyMap = Map as ReadonlyMapConstructor;
It produces the following output in a ".d.ts" file:
interface ReadonlyMapConstructor {
new (): ReadonlyMap$1<any, any>;
new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | Iterable<readonly [K, V]> | null): ReadonlyMap$1<K, V>;
readonly prototype: ReadonlyMap$1<any, any>;
}
/** An alias for the `Map` constructor that returns a read-only map. */
declare const ReadonlyMap$1: ReadonlyMapConstructor;
There are two problems with this:
- If we import the library and do
const FOO = new ReadonlyMap<string, string>();and we mouse overFOO, we see that the type isReadonlyMap$1<K, V>instead ofReadonlyMap<K, V>. That's a problem. In other words, if we are exporting helper types to consumers, we don't want those types mangled. - More importantly, the "@typescript-eslint/no-unsafe-assignment" rule flags this as an
anyvalue, because the ".d.ts" has errors in it.
Can you confirm it with the latest unbuild? I tried it, the current output is:
interface ReadonlyMapConstructor {
new (): ReadonlyMap<any, any>;
new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | Iterable<readonly [K, V]> | null): ReadonlyMap<K, V>;
readonly prototype: ReadonlyMap<any, any>;
}
/** An alias for the `Map` constructor that returns a read-only map. */
declare const ReadonlyMap: ReadonlyMapConstructor;
export { ReadonlyMap };
It seems that this issue has been resolved.