tsdjs / tsd

Check TypeScript type definitions
MIT License
2.38k stars 68 forks source link

mapped type with indexing throws error #125

Open ianjkaplan opened 2 years ago

ianjkaplan commented 2 years ago

Hello,

I have the following code in a type definition file i want to test


interface BaseQueues<Q extends Queue = Queue> {
    someQueue: Q;
}

interface Crons {
    someCron: { nightly: { name: string; cron: string } };
    someOtherCron: { nightly: { name: string; cron: string } };
}

type ConcreteQueues<BaseQueues> = {
    [P in keyof BaseQueues]: Crons[P] extends object
        ? Crons[P] & BaseQueues[P]
        : BaseQueues[P];
};

this code does not produce any compile time errors when creating a ConcreteQueue and accessing someQueue.someCron.nightly etc. However when i run tsd i get Type P cannot be used to index type Crons. Maybe its an issue with my type definition above? Can someone explain why this might be happening?

Thanks in advance. I appreciate the tool!

BendingBender commented 2 years ago

Possibly a TypeScript version mismatch? What TypeScript version do you use in your project? tsd currently uses TypeScript 4.3.