microsoft / microsoft/TypeScript

unused type declaration causes totally unrelated error (Index signatures are incompatible)

オープン
#45,258 コメント 2 件 リアクション 5 件 担当者 1 名 GitHub で見る

@armanio123 がすでに取り組んでいます。

2021年8月2日 から。

Bug Domain: check: Error Instability Rescheduled
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

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);

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。