microsoft / microsoft/TypeScript

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

Aperta
#57,564 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: Something Else Has Repro Needs Human Review Needs More Info
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione collegata in TypeScript bug-workbench Playground e confronta il comportamento di T[] con quello di Array quando global Array è un literal di tipo oggetto. Traccia il modo in cui il compilatore gestisce l'alias globale Array, la sintassi degli array e l'assegnabilità. Il lavoro è completato se entrambe le forme si comportano in modo sinonimo oppure se il tipo Array non valido produce un errore del compilatore, con le aspettative della riproduzione coperte da un test di regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
52/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.