index.d.ts broken - "Type 'U' cannot be used to index type 'T'."
shoffmeister opened this issue · 6 comments
Description
The index.d.ts
generated for openapi-fetch
causes (my) Typescript compiler to complain "Type 'U' cannot be used to index type 'T'."
Reproduction
- Clean plate
git clone https://github.com/drwpow/openapi-fetch.git
git checkout v0.0.6
cd openapi-fetch
npm install
- Place attached file repro.ts.txt as
repro.ts
into the root of the repository npx tsc repro.ts
// exp: no diagnostics
//act:
Type 'U' cannot be used to index type 'T'.
Type 'M' cannot be used to index type 'T[U]'.
Trigger is the following part in index.d.ts
:
export default function createClient<T>(defaultOptions?: ClientOptions): {
/** Call a GET endpoint */
get<U extends { [Path in keyof T]: T[Path] extends {
get: unknown;
} ? Path : never; }[keyof T], M extends keyof T[U]>(url: U, options: (T[U][M] extends infer T ? T extends T[U][M] ? T extends {
parameters: any;
} ? {
Perhaps my package-lock.json provides additional clues? See package-lock.json.gz
FWIW, the raw Typescript file - i.e. index.ts
as shipped via npm
- is doing fine.
Vendoring this file works, but doing that quite obviously is The Wrong Thing to do :)
What TypeScript version are you using? I recently upgraded to 5.x and noticed some slight differences and wondering if there’s a 4.x <> 5.x error
With the package-lock.json
(above) this is 5.0.4; I think I tried 4.9.5, too (with the same result) - and when I noticed that your package.json
had ^5.0.3, I simply created this issue here.
I am on Fedora Linux 37, and the only global Javascript / Typescript bits and pieces are "dnf install nodejs" (which is 18.9.5 right now IIRC). The rest all comes via npm
into local node_modules
.
Same issue, TS 5.0.3
upd: downgrade to 4.9.5 didn't help either
upd2: had to set "skipLibCheck": true,
to overcome issue
Ah I’m seeing this as well :/. It only seems to exist in the built types, not the source files. Not sure if it’s a TypeScript bug or what. But this should be fixable.
skipLibCheck: true
is recommended as a workaround for now.