microsoft / microsoft/TypeScript
unused type declaration causes totally unrelated error (Index signatures are incompatible)
Open
@armanio123 is already working on this.
Since Aug 2, 2021.
Bug
Domain: check: Error Instability
Rescheduled
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🕗 Version & Regression Information
Getting same error on all versions I tried.
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Ref<Prefix extends string> {
$ref: string;
prefix: Prefix;
}
type FFF = { faa: number };
// if you comment this line out the error will disappear
// NOTE THIS TYPE IS NOT USED AT ALL 😱
type KAMIKADZE = { asdasdasd: Record<string, FFF>; }
declare const x: {
responses: Record<string, number>;
fff: Record<string, FFF>;
};
// if you comment out first declaration of `KAMIKADZE` and uncomment this one
// THE ERROR WILL disappear 😱
// type KAMIKADZE = { asdasdasd: Record<string, FFF>; }
mustResolveRef({ $ref: "", prefix: "responses" }, x);
// ___^^^___
// Argument of type '{ responses: Record<string, number>; fff: Record<string, FFF>; }' is not assignable to parameter of type 'Record<"responses", Record<string, FFF>>'.
// Types of property 'responses' are incompatible.
// Type 'Record<string, number>' is not assignable to type 'Record<string, FFF>'.
// Index signatures are incompatible.
// Type 'number' is not assignable to type 'FFF'.
declare function mustResolveRef<T extends string, V>(
ref: Ref<T>,
components: Record<T, Record<string, V>>
): V | undefined
🙁 Actual behavior
Actual behavior is super strange. tried to express this in code comments.
🙂 Expected behavior
It's expected that, having some type declaration, that's not used and is not in conflict with anything, to not cause totally unrelated error.
Plus the error itself shouldn't be thrown as if I do this, all works fine:
const y: Pick<typeof x,"responses"> = x
mustResolveRef({ $ref: "", prefix: "responses" }, y);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.