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

types inside .d.ts files are bugged #347

Open
Zamiell opened this issue Dec 15, 2023 · 0 comments
Open

types inside .d.ts files are bugged #347

Zamiell opened this issue Dec 15, 2023 · 0 comments

Comments

@Zamiell
Copy link

Zamiell commented Dec 15, 2023

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:

  1. If we import the library and do const FOO = new ReadonlyMap<string, string>(); and we mouse over FOO, we see that the type is ReadonlyMap$1<K, V> instead of ReadonlyMap<K, V>. That's a problem. In other words, if we are exporting helper types to consumers, we don't want those types mangled.
  2. More importantly, the "@typescript-eslint/no-unsafe-assignment" rule flags this as an any value, because the ".d.ts" has errors in it.
@Zamiell Zamiell changed the title types are bugged types inside .d.ts files are bugged Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant