microsoft / microsoft/TypeScript

Error not issued when global type is an alias of an object type literal

オープン
#57,564 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Bug Domain: Something Else Has Repro Needs Human Review Needs More Info
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

array, constructor, bracket

🕗 Version & Regression Information
  • This is a crash
⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?noLib=true&target=99&ts=5.5.0-dev.20240227#code/PTAEAEDsHsBkEsBGAuUAXATgVwKYCgQI0BDDAcxzVRwGdIcAPNPPAExwGMAbUnUMrtETEuoAN55QoDtEg00oAIIYMxAJ6oJUqQB4AKqAC8oLJADWMAO6QAfAAoAdE9JkayYpDUBtALoBKVGVVNX0bSW16S1B9IxNzK0gAGnsnBxc3D29-QJV1UPCAXxYpNDUABz4gvL0bWK1tL3hUSCwAW0QcDB9UPXCpLhxIMjQAC2a2joxCvCKCMBFRaAAzdBG+DsEosngANz4AIgAFDGgKjFLQAHIBodHL0HgaUFbHmnghh8h0cr5LsQLLql9sg8ABuUB2LwARkSoAATLCAMz+UA0YhoR5LeC0JS5EItdqdGygsEQ6GwhGgZF+VHozHYp5iUA3YZjUAEyagAok9jcXjSWTyUCkKHNHB7DC+Uki2kYmhYnFMlmjcaEjBcnmcHgYPgyOQKUhw1WTKXgw2y+mK5mDVnGzpclhzVaPVEjaBYLisVYnKIeUCdE7qxBYBTwBSsaC0SCXZiEcBoGgAWkYFQ4aGTKmgU3BkJ8wqeHM6vhpaLlCqe8gw7zIUrwKazCiZBSAA

💻 Code
// @noLib: true
// @target: esnext

declare global {
  const Array: {
    <T = unknown>(...args:any[]): Array<T>
    new <T = unknown,>(...args:any[]): Array<T>
  }

  type Array<T> = {
    [i: number]: T
    length: number
  }
}

// all of the below give "Property 'length' is missing in type '{}'...":
; ([1, 2, 3]) satisfies Array<number>;
; ([1, 2, 3]) satisfies { length: number };
declare const ar1: never[]
; ar1 satisfies { length: number };
declare const ar2: number[]
; ar2 satisfies { length: number }


// this should throw an error but it doesn't
// @ts-expect-error
; ([] as number[]) satisfies string[]

export { }
🙁 Actual behavior

Types created with the T[] and objects created with the [x as T] syntax are not typed as Array<T> but instead as {}.

🙂 Expected behavior

I expect either:

  • T[] syntax and Array<T> to be completely synonymous
  • A compiler error that the Array type is not an instantiable type
Additional information about the issue

Related to #57009.

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript bug-workbench Playground の再現コードから始め、global Array がオブジェクト型リテラルである場合の T[] と Array の挙動を比較します。コンパイラーが global Array エイリアス、配列構文、代入可能性をどのように処理するかを追跡します。完了条件は、両方の形式が同義に振る舞うか、無効な Array 型がコンパイラーエラーを生成し、再現コードの期待値が回帰テストでカバーされることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

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

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